Skip to content

Commit 17a5d5a

Browse files
committed
Merge branch 'master' of github.com:Automattic/mongoose
2 parents 041be89 + 57834e2 commit 17a5d5a

File tree

15 files changed

+35
-33
lines changed

15 files changed

+35
-33
lines changed

benchmarks/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ function run(label, fn) {
7575
res.heapUsed = used.heapUsed - started.heapUsed;
7676
log('change: ', res);
7777
a = res = used = time = started = start = total = i = null;
78-
// console.error(((used.vsize - started.vsize) / 1048576)+' MB');
7978
}
8079

8180
run('string', function() {

benchmarks/validate.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// require('nodetime').profile();
2-
31
'use strict';
42

53
const mongoose = require('../../mongoose');
@@ -25,8 +23,7 @@ const breakfastSchema = new Schema({
2523
}
2624
});
2725
const Breakfast = mongoose.model('Breakfast', breakfastSchema);
28-
// const time1 = (new Date - start1);
29-
// console.error('reading from disk and parsing JSON took %d ms', time1);
26+
3027
const badBreakfast = new Breakfast({
3128
eggs: 2,
3229
bacon: 0,
@@ -38,23 +35,7 @@ const goodBreakfast = new Breakfast({
3835
bacon: 1,
3936
drink: 'Tea'
4037
})
41-
// const start = new Date;
42-
// const total = 10000000;
43-
// let i = total;
44-
// let len;
45-
46-
// for (i = 0, len = total; i < len; ++i) {
47-
48-
// const goodBreakfast = new Breakfast({
49-
// eggs: 6,
50-
// bacon: 1,
51-
// drink: 'Tea'
52-
// })
53-
// goodBreakfast.validateSync();
54-
// }
5538

56-
// const time = (new Date - start) / 1000;
57-
// console.error('took %d seconds for %d docs (%d dps)', time, total, total / time);
5839
const suite = new Benchmark.Suite()
5940
suite
6041
.add('invalid async', {

examples/statics/statics.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function run() {
2424
const result = await Person.findPersonByName('bill');
2525

2626
console.log(result);
27-
cleanup();
27+
await cleanup();
2828
}
2929

3030
async function cleanup() {

lib/browserDocument.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const isObject = require('./helpers/isObject');
1717
* Document constructor.
1818
*
1919
* @param {Object} obj the values to set
20+
* @param {Object} schema
2021
* @param {Object} [fields] optional object containing the fields which were selected in the query returning this document and any populated paths data
2122
* @param {Boolean} [skipId] bool, should we auto create an ObjectId _id
2223
* @inherits NodeJS EventEmitter https://nodejs.org/api/events.html#events_class_events_eventemitter

lib/cursor/AggregationCursor.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const util = require('util');
2626
* Use [`Aggregate#cursor()`](/docs/api.html#aggregate_Aggregate-cursor) instead.
2727
*
2828
* @param {Aggregate} agg
29-
* @param {Object} options
3029
* @inherits Readable
3130
* @event `cursor`: Emitted when the cursor is created
3231
* @event `error`: Emitted when an error occurred

lib/helpers/query/castFilterPath.js

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ module.exports = function castFilterPath(query, schematype, val) {
4141
}
4242
continue;
4343
}
44-
// cast(schematype.caster ? schematype.caster.schema : schema, nested, options, context);
4544
} else {
4645
val[$cond] = schematype.castForQueryWrapper({
4746
$conditional: $cond,

lib/model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ Model.discriminators;
18851885
* ####Note:
18861886
* Only translate arguments of object type anything else is returned raw
18871887
*
1888-
* @param {Object} raw fields/conditions that may contain aliased keys
1888+
* @param {Object} fields fields/conditions that may contain aliased keys
18891889
* @return {Object} the translated 'pure' fields/conditions
18901890
*/
18911891
Model.translateAliases = function translateAliases(fields) {

lib/schema/SubdocumentPath.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = SubdocumentPath;
2626
* Single nested subdocument SchemaType constructor.
2727
*
2828
* @param {Schema} schema
29-
* @param {String} key
29+
* @param {String} path
3030
* @param {Object} options
3131
* @inherits SchemaType
3232
* @api public

lib/schema/array.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const emptyOpts = Object.freeze({});
3232
* @param {String} key
3333
* @param {SchemaType} cast
3434
* @param {Object} options
35+
* @param {Object} schemaOptions
3536
* @inherits SchemaType
3637
* @api public
3738
*/

lib/schema/documentarray.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ let Subdocument;
3030
* @param {String} key
3131
* @param {Schema} schema
3232
* @param {Object} options
33+
* @param {Object} schemaOptions
3334
* @inherits SchemaArray
3435
* @api public
3536
*/

lib/types/array/methods/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ const methods = {
445445
* Return whether or not the `obj` is included in the array.
446446
*
447447
* @param {Object} obj the item to check
448+
* @param {Number} fromIndex
448449
* @return {Boolean}
449450
* @api public
450451
* @method includes
@@ -460,6 +461,7 @@ const methods = {
460461
* Return the index of `obj` or `-1` if not found.
461462
*
462463
* @param {Object} obj the item to look for
464+
* @param {Number} fromIndex
463465
* @return {Number}
464466
* @api public
465467
* @method indexOf

lib/virtualtype.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const utils = require('./utils');
2424
* @param {Number} [options.skip=null] add a default `skip` to the `populate()` query
2525
* @param {Number} [options.perDocumentLimit=null] For legacy reasons, `limit` with `populate()` may give incorrect results because it only executes a single query for every document being populated. If you set `perDocumentLimit`, Mongoose will ensure correct `limit` per document by executing a separate query for each document to `populate()`. For example, `.find().populate({ path: 'test', perDocumentLimit: 2 })` will execute 2 additional queries if `.find()` returns 2 documents.
2626
* @param {Object} [options.options=null] Additional options like `limit` and `lean`.
27+
* @param {string} name
2728
* @api public
2829
*/
2930

test/index.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ describe('mongoose module:', function() {
773773

774774
const movie = await Movie.create({ name: 'The Empire Strikes Back' });
775775
await Person.create({ name: 'Test1', favoriteMovie: movie._id });
776-
assert.rejects(async() => {
776+
await assert.rejects(async() => {
777777
await Person.findOne().populate({ path: 'favoriteGame' });
778778
}, { message: 'Cannot populate path `favoriteGame` because it is not in your schema. Set the `strictPopulate` option to false to override.' });
779779
});
@@ -788,7 +788,7 @@ describe('mongoose module:', function() {
788788
}));
789789
const movie = await Movie.create({ name: 'The Empire Strikes Back' });
790790
await Person.create({ name: 'Test1', favoriteMovie: movie._id });
791-
assert.rejects(async() => {
791+
await assert.rejects(async() => {
792792
await Person.findOne().populate({ path: 'favoriteGame', strictPopulate: true });
793793
}, { message: 'Cannot populate path `favoriteGame` because it is not in your schema. Set the `strictPopulate` option to false to override.' });
794794
});
@@ -912,4 +912,4 @@ describe('mongoose module:', function() {
912912
assert.deepEqual(await m.syncIndexes(), {});
913913
});
914914
});
915-
});
915+
});

test/types/populate.test.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,37 @@ function gh11503() {
164164
interface User {
165165
friends: Types.ObjectId[];
166166
}
167-
const UserSchema = new Schema<User>({
167+
const userSchema = new Schema<User>({
168168
friends: [{ type: Schema.Types.ObjectId, ref: 'friends' }]
169169
});
170-
const Users = model<User>('friends', UserSchema);
170+
const User = model<User>('friends', userSchema);
171171

172-
Users.findOne({}).populate('friends').then(user => {
172+
User.findOne({}).populate('friends').then(user => {
173173
expectType<Types.ObjectId | undefined>(user?.friends[0]);
174174
expectError(user?.friends[0].blocked);
175175
expectError(user?.friends.map(friend => friend.blocked));
176176
});
177177

178-
Users.findOne({}).populate<{friends: Friend[]}>('friends').then(user => {
178+
User.findOne({}).populate<{friends: Friend[]}>('friends').then(user => {
179179
expectAssignable<Friend>(user?.friends[0]);
180180
expectType<boolean>(user?.friends[0].blocked);
181181
const firstFriendBlockedValue = user?.friends.map(friend => friend)[0];
182182
expectType<boolean>(firstFriendBlockedValue?.blocked);
183183
});
184+
}
185+
186+
187+
function gh11544() {
188+
189+
interface User {
190+
friends: Types.ObjectId[];
191+
}
192+
const userSchema = new Schema<User>({
193+
friends: [{ type: Schema.Types.ObjectId, ref: 'friends' }]
194+
});
195+
const User = model<User>('friends', userSchema);
196+
197+
User.findOne({}).populate({ path: 'friends', strictPopulate: false });
198+
User.findOne({}).populate({ path: 'friends', strictPopulate: true });
199+
User.findOne({}).populate({ path: 'friends', populate: { path: 'someNestedPath', strictPopulate: false } });
184200
}

types/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ declare module 'mongoose' {
709709
model?: string | Model<any>;
710710
/** optional query options like sort, limit, etc */
711711
options?: any;
712+
/** optional boolean, set to `false` to allow populating paths that aren't in the schema */
713+
strictPopulate?: boolean;
712714
/** deep populate */
713715
populate?: string | PopulateOptions | (string | PopulateOptions)[];
714716
/**

0 commit comments

Comments
 (0)