Skip to content

Commit 27a515a

Browse files
Merge pull request #27 from nazar-i/feature/clarify-findOneAndUpsert-behavior-in-doc
Clarify findOneAndUpsert behavior in doc
2 parents 35b8f17 + fe8b4d7 commit 27a515a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
577577

578578
Upsert a single document on MongoDB.
579579

580+
**⚠️ Important**. Uses [`findOneAnReplace`](https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndReplace) and [`findOneAndUpdate`](https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndUpdate) with `upsert` option under the hood.
581+
`findOneAndReplace` will be used, if update parameter do not contain any [update operators](https://docs.mongodb.com/v3.6/reference/operator/update/) (basically, fields begins with `$`). It can lead to slightly inconsistent behavior, depending on input data. (see [db.collection.findOneAndReplace-upsert](https://docs.mongodb.com/v3.6/reference/method/db.collection.findOneAndReplace/#findoneandreplace-upsert) and [db.collection.update upsert behavior](https://docs.mongodb.com/v3.6/reference/method/db.collection.update/#upsert-behavior) to clarify behavior difference). Because of realization it's **strongly not recommended** using this method on collection with `sequenceId` and `updateDate` plugins.
582+
580583
###### Parameters:
581584

582585
* **filter**, object. The Filter used to select the document to upsert
@@ -1159,6 +1162,8 @@ MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
11591162

11601163
Replace mongo-style object _id with number.
11611164

1165+
⚠️ Do not work with [`findOneAndUpsert()`](#findoneandupsert).
1166+
11621167
**options:**
11631168

11641169
* `seqCollectionName` - name of sequences collection ('__sequences' by default)
@@ -1182,6 +1187,8 @@ Add createDate to each inserted to collection document
11821187

11831188
Add updateDate to each updated or replaces document
11841189

1190+
⚠️ Do not work properly with [`findOneAndUpsert()`](#findoneandupsert), `createDate` will be rewrote every time.
1191+
11851192
**options:**
11861193

11871194
* `format` - date format that will be used as `updateDate`, available values:

0 commit comments

Comments
 (0)