Skip to content

Commit fa0fb22

Browse files
committed
Merge branch '9.2'
2 parents 067b3d8 + f72bd53 commit fa0fb22

18 files changed

+320
-97
lines changed

docs/source/api.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,18 @@ function processName(input) {
209209
}
210210

211211
// helper function to keep translating array types to string consistent
212-
function convertTypesToString(types) {
213-
return Array.isArray(types) ? types.join('|') : types;
212+
// typesDescription is used as fallback when types contains '[object Object]'
213+
// (happens with string literal types like 'before'|'after' due to dox/jsdoctypeparser bug)
214+
function convertTypesToString(types, typesDescription) {
215+
if (!Array.isArray(types)) {
216+
return types;
217+
}
218+
const result = types.join('|');
219+
if (result.includes('[object Object]') && typesDescription) {
220+
// Strip HTML code tags from typesDescription: <code>foo</code> -> foo
221+
return typesDescription.replace(/<\/?code>/g, '');
222+
}
223+
return result;
214224
}
215225

216226
/**
@@ -295,12 +305,12 @@ function processFile(props) {
295305
ctx.name = tag.name;
296306
// only assign "type" if there are types
297307
if (tag.types.length > 0) {
298-
ctx.type = convertTypesToString(tag.types);
308+
ctx.type = convertTypesToString(tag.types, tag.typesDescription);
299309
}
300310

301311
break;
302312
case 'type':
303-
ctx.type = convertTypesToString(tag.types);
313+
ctx.type = convertTypesToString(tag.types, tag.typesDescription);
304314
break;
305315
case 'static':
306316
ctx.type = 'property';
@@ -359,7 +369,7 @@ function processFile(props) {
359369
tag.types.push('null');
360370
}
361371
if (tag.types) {
362-
tag.types = convertTypesToString(tag.types);
372+
tag.types = convertTypesToString(tag.types, tag.typesDescription);
363373
}
364374
ctx[tag.type].push(tag);
365375
if (tag.name != null && tag.name.startsWith('[') && tag.name.endsWith(']') && tag.name.includes('.')) {

docs/timestamps.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ await doc.save();
2222
console.log(doc.createdAt); // 2022-02-26T16:37:48.244Z
2323
console.log(doc.updatedAt); // 2022-02-26T16:37:48.307Z
2424

25-
doc = await User.findOneAndUpdate({ _id: doc._id }, { name: 'test3' }, { new: true });
25+
doc = await User.findOneAndUpdate({ _id: doc._id }, { name: 'test3' }, { returnDocument: 'after' });
2626
console.log(doc.createdAt); // 2022-02-26T16:37:48.244Z
2727
console.log(doc.updatedAt); // 2022-02-26T16:37:48.366Z
2828
```
@@ -51,7 +51,7 @@ console.log(doc.updatedAt); // 2022-02-26T17:08:13.991Z
5151
doc = await User.findOneAndUpdate(
5252
{ _id: doc._id },
5353
{ name: 'test3', createdAt: new Date(0), updatedAt: new Date(0) },
54-
{ new: true }
54+
{ returnDocument: 'after' }
5555
);
5656
console.log(doc.createdAt); // 2022-02-26T17:08:13.930Z
5757
console.log(doc.updatedAt); // 2022-02-26T17:08:14.008Z
@@ -66,7 +66,7 @@ Calling `replaceOne()` or `findOneAndReplace()` will update the `createdAt` time
6666
doc = await User.findOneAndReplace(
6767
{ _id: doc._id },
6868
{ name: 'test3' },
69-
{ new: true }
69+
{ returnDocument: 'after' }
7070
);
7171
console.log(doc.createdAt); // 2022-02-26T17:08:14.008Z
7272
console.log(doc.updatedAt); // 2022-02-26T17:08:14.008Z
@@ -80,7 +80,7 @@ doc = await User.findOneAndReplace(
8080
createdAt: new Date('2022-06-01'),
8181
updatedAt: new Date('2022-06-01')
8282
},
83-
{ new: true }
83+
{ returnDocument: 'after' }
8484
);
8585
console.log(doc.createdAt); // 2022-06-01T00:00:00.000Z
8686
console.log(doc.updatedAt); // 2022-06-01T00:00:00.000Z
@@ -120,7 +120,7 @@ console.log(doc.updatedAt); // 2022-02-26T23:28:54.264Z
120120
// Similarly, setting `timestamps: false` on a query tells Mongoose to skip updating
121121
// `updatedAt`.
122122
doc = await User.findOneAndUpdate({ _id: doc._id }, { name: 'test3' }, {
123-
new: true,
123+
returnDocument: 'after',
124124
timestamps: false
125125
});
126126
console.log(doc.updatedAt); // 2022-02-26T23:28:54.264Z
@@ -159,15 +159,15 @@ let doc = await User.create({ name: 'test' });
159159
// To update `updatedAt`, do a `findOneAndUpdate()` with `timestamps: false` and
160160
// `updatedAt` set to the value you want
161161
doc = await User.findOneAndUpdate({ _id: doc._id }, { updatedAt: new Date(0) }, {
162-
new: true,
162+
returnDocument: 'after',
163163
timestamps: false
164164
});
165165
console.log(doc.updatedAt); // 1970-01-01T00:00:00.000Z
166166

167167
// To update `createdAt`, you also need to set `strict: false` because `createdAt`
168168
// is immutable
169169
doc = await User.findOneAndUpdate({ _id: doc._id }, { createdAt: new Date(0) }, {
170-
new: true,
170+
returnDocument: 'after',
171171
timestamps: false,
172172
strict: false
173173
});

docs/tutorials/findoneandupdate.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,17 @@ In the following example, `doc` initially only has `name` and `_id` properties.
2626
[require:Tutorial.*findOneAndUpdate.*basic case]
2727
```
2828

29-
You should set the `new` option to `true` to return the document **after** `update` was applied.
29+
You should set the `returnDocument` option to `'after'` to return the document **after** `update` was applied.
3030

3131
```acquit
32-
[require:Tutorial.*findOneAndUpdate.*new option]
32+
[require:Tutorial.*findOneAndUpdate.*returnDocument option]
3333
```
3434

3535
Mongoose's `findOneAndUpdate()` is slightly different from [the MongoDB Node.js driver's `findOneAndUpdate()`](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate) because it returns the document itself, not a [result object](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#~findAndModifyWriteOpResult).
3636

37-
As an alternative to the `new` option, you can also use the `returnOriginal` option.
38-
`returnOriginal: false` is equivalent to `new: true`. The `returnOriginal` option
39-
exists for consistency with the [the MongoDB Node.js driver's `findOneAndUpdate()`](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate),
40-
which has the same option.
41-
42-
```acquit
43-
[require:Tutorial.*findOneAndUpdate.*returnOriginal option]
44-
```
37+
The `new` and `returnOriginal` options are **deprecated** in favor of `returnDocument`.
38+
Use `returnDocument: 'after'` instead of `new: true` or `returnOriginal: false`.
39+
Use `returnDocument: 'before'` instead of `new: false` or `returnOriginal: true`.
4540

4641
## Atomic Updates
4742

lib/aggregate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ Aggregate.prototype.read = function(pref, tags) {
719719
*
720720
* await Model.aggregate(pipeline).readConcern('majority');
721721
*
722-
* @param {String} level one of the listed read concern level or their aliases
722+
* @param {'local'|'available'|'majority'|'snapshot'|'linearizable'|'l'|'a'|'m'|'s'|'lz'} level one of the listed read concern level or their aliases
723723
* @see mongodb https://www.mongodb.com/docs/manual/reference/read-concern/
724724
* @return {Aggregate} this
725725
* @api public
@@ -785,7 +785,7 @@ Aggregate.prototype.redact = function(expression, thenExpr, elseExpr) {
785785
*
786786
* Model.aggregate(..).explain()
787787
*
788-
* @param {String} [verbosity]
788+
* @param {'queryPlanner'|'executionStats'|'allPlansExecution'} [verbosity]
789789
* @return {Promise}
790790
*/
791791

lib/cursor/aggregationCursor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ function _transformForAsyncIterator(doc) {
389389
* Adds a [cursor flag](https://mongodb.github.io/node-mongodb-native/4.9/classes/AggregationCursor.html#addCursorFlag).
390390
* Useful for setting the `noCursorTimeout` and `tailable` flags.
391391
*
392-
* @param {String} flag
392+
* @param {'tailable'|'oplogReplay'|'noCursorTimeout'|'awaitData'|'partial'} flag
393393
* @param {Boolean} value
394394
* @return {AggregationCursor} this
395395
* @api public

lib/cursor/queryCursor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ QueryCursor.prototype.options;
371371
* Adds a [cursor flag](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html#addCursorFlag).
372372
* Useful for setting the `noCursorTimeout` and `tailable` flags.
373373
*
374-
* @param {String} flag
374+
* @param {'tailable'|'oplogReplay'|'noCursorTimeout'|'awaitData'|'partial'} flag
375375
* @param {Boolean} value
376376
* @return {AggregationCursor} this
377377
* @api public

lib/document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ function init(self, obj, doc, opts, prefix) {
861861
* @param {Object} update
862862
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
863863
* @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and the [Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
864-
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
864+
* @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
865865
* @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
866866
* @param {Boolean|Object} [options.middleware=true] set to `false` to skip all user-defined middleware
867867
* @param {Boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks

lib/helpers/query/castUpdate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const mongodbUpdateOperators = new Set([
4141
* @param {Schema} schema
4242
* @param {Object} obj
4343
* @param {Object} [options]
44-
* @param {Boolean|String} [options.strict] defaults to true
44+
* @param {Boolean|'throw'} [options.strict] defaults to true
4545
* @param {Query} context passed to setters
4646
* @return {Boolean} true iff the update is non-empty
4747
* @api private
@@ -205,7 +205,7 @@ function castPipelineOperator(op, val) {
205205
* @param {Object} obj part of a query
206206
* @param {String} op the atomic operator ($pull, $set, etc)
207207
* @param {Object} [options]
208-
* @param {Boolean|String} [options.strict]
208+
* @param {Boolean|'throw'} [options.strict]
209209
* @param {Query} context
210210
* @param {Object} filter
211211
* @param {String} pref path prefix (internal only)

0 commit comments

Comments
 (0)