@@ -51,10 +51,6 @@ const docs = await Artist().find(...).where(...);
51
51
- [ find()] ( #find )
52
52
- [ findOne()] ( #findone )
53
53
- [ count()] ( #count )
54
- - [ remove()] ( #remove )
55
- - [ update()] ( #update )
56
- - [ the update document] ( #the-update-document )
57
- - [ update() options] ( #update-options )
58
54
- [ findOneAndUpdate()] ( #findoneandupdate )
59
55
- [ findOneAndUpdate() options] ( #findoneandupdate-options )
60
56
- [ findOneAndRemove()] ( #findoneandremove )
@@ -102,7 +98,6 @@ const docs = await Artist().find(...).where(...);
102
98
- [ hint()] ( #hint )
103
99
- [ j()] ( #j )
104
100
- [ limit()] ( #limit )
105
- - [ maxScan()] ( #maxscan )
106
101
- [ maxTime()] ( #maxtime )
107
102
- [ skip()] ( #skip )
108
103
- [ sort()] ( #sort )
@@ -114,7 +109,6 @@ const docs = await Artist().find(...).where(...);
114
109
- [ writeConcern()] ( #writeconcern )
115
110
- [ Write Concern:] ( #write-concern )
116
111
- [ slaveOk()] ( #slaveok )
117
- - [ snapshot()] ( #snapshot )
118
112
- [ tailable()] ( #tailable )
119
113
- [ wtimeout()] ( #wtimeout )
120
114
- [ Helpers] ( #helpers-1 )
@@ -187,99 +181,6 @@ const number = await mquery().count(match);
187
181
console .log (' we found %d matching documents' , number);
188
182
```
189
183
190
- ### remove()
191
-
192
- Declares this query a _ remove_ query. Optionally pass a match clause.
193
-
194
- ``` js
195
- mquery ().remove ()
196
- mquery ().remove (match)
197
- await mquery ().remove ()
198
- await mquery ().remove (match)
199
- ```
200
-
201
- ### update()
202
-
203
- Declares this query an _ update_ query. Optionally pass an update document, match clause, options.
204
-
205
- ``` js
206
- mquery ().update ()
207
- mquery ().update (match, updateDocument)
208
- mquery ().update (match, updateDocument, options)
209
-
210
- // the following all execute the command
211
- await mquery ().update ()
212
- await mquery ().update ({ $set: updateDocument })
213
- await mquery ().update (match, updateDocument)
214
- await mquery ().update (match, updateDocument, options)
215
- ```
216
-
217
- #### the update document
218
-
219
- All paths passed that are not ` $atomic ` operations will become ` $set ` ops. For example:
220
-
221
- ``` js
222
- await mquery (collection).where ({ _id: id }).update ({ title: ' words' })
223
- ```
224
-
225
- becomes
226
-
227
- ``` js
228
- await collection .update ({ _id: id }, { $set: { title: ' words' } })
229
- ```
230
-
231
- This behavior can be overridden using the ` overwrite ` option (see below).
232
-
233
- #### update() options
234
-
235
- Options are passed to the ` setOptions() ` method.
236
-
237
- - overwrite
238
-
239
- Passing an empty object ` { } ` as the update document will result in a no-op unless the ` overwrite ` option is passed. Without the ` overwrite ` option, the update operation will be ignored and the promise resolved without sending the command to MongoDB to prevent accidently overwritting documents in the collection.
240
-
241
- ``` js
242
- var q = mquery (collection).where ({ _id: id }).setOptions ({ overwrite: true });
243
- await q .update ({ }); // overwrite with an empty doc
244
- ```
245
-
246
- The ` overwrite ` option isn't just for empty objects, it also provides a means to override the default ` $set ` conversion and send the update document as is.
247
-
248
- ``` js
249
- // create a base query
250
- var base = mquery ({ _id: 108 }).collection (collection).toConstructor ();
251
-
252
- const doc = await base ().findOne ();
253
- console .log (doc); // { _id: 108, name: 'cajon' })
254
-
255
- await base ().setOptions ({ overwrite: true }).update ({ changed: true });
256
- const doc2 = base .findOne ();
257
- console .log (doc2); // { _id: 108, changed: true }) - the doc was overwritten
258
- ```
259
-
260
- - multi
261
-
262
- Updates only modify a single document by default. To update multiple documents, set the ` multi ` option to ` true ` .
263
-
264
- ``` js
265
- await mquery ()
266
- .collection (coll)
267
- .update ({ name: / ^ match/ }, { $addToSet: { arr: 4 }}, { multi: true })
268
-
269
- // another way of doing it
270
- await mquery ({ name: / ^ match/ })
271
- .collection (coll)
272
- .setOptions ({ multi: true })
273
- .update ({ $addToSet: { arr: 4 }})
274
-
275
- // update multiple documents with an empty doc
276
- var q = mquery (collection).where ({ name: / ^ match/ });
277
- q .setOptions ({ multi: true , overwrite: true })
278
- q .update ({ });
279
- const result = await q .update ();
280
- console .log (result);
281
- ```
282
-
283
184
### findOneAndUpdate()
284
185
285
186
Declares this query a _ findAndModify_ with update query. Optionally pass a match clause, update document, options.
@@ -896,8 +797,6 @@ This option is only valid for operations that write to the database:
896
797
- ` deleteMany() `
897
798
- ` findOneAndDelete() `
898
799
- ` findOneAndUpdate() `
899
- - ` remove() `
900
- - ` update() `
901
800
- ` updateOne() `
902
801
- ` updateMany() `
903
802
@@ -919,18 +818,6 @@ _Cannot be used with `distinct()`._
919
818
920
819
[ MongoDB documentation] ( http://docs.mongodb.org/manual/reference/method/cursor.limit/ )
921
820
922
- ### maxScan()
923
-
924
- Specifies the maxScan option.
925
-
926
- ``` js
927
- query .maxScan (100 )
928
- ```
929
-
930
- _ Cannot be used with ` distinct() ` ._
931
-
932
- [ MongoDB documentation] ( http://docs.mongodb.org/manual/reference/operator/maxScan/ )
933
-
934
821
### maxTime()
935
822
936
823
Specifies the maxTimeMS option.
@@ -1087,8 +974,6 @@ This option is only valid for operations that write to the database:
1087
974
- ` deleteMany() `
1088
975
- ` findOneAndDelete() `
1089
976
- ` findOneAndUpdate() `
1090
- - ` remove() `
1091
- - ` update() `
1092
977
- ` updateOne() `
1093
978
- ` updateMany() `
1094
979
@@ -1130,20 +1015,6 @@ query.slaveOk(false)
1130
1015
1131
1016
[ MongoDB documentation] ( http://docs.mongodb.org/manual/reference/method/rs.slaveOk/ )
1132
1017
1133
- ### snapshot()
1134
-
1135
- Specifies this query as a snapshot query.
1136
-
1137
- ``` js
1138
- mquery ().snapshot () // true
1139
- mquery ().snapshot (true )
1140
- mquery ().snapshot (false )
1141
- ```
1142
-
1143
- _ Cannot be used with ` distinct() ` ._
1144
-
1145
- [ MongoDB documentation] ( http://docs.mongodb.org/manual/reference/operator/snapshot/ )
1146
-
1147
1018
### tailable()
1148
1019
1149
1020
Sets tailable option.
@@ -1169,8 +1040,6 @@ This option is only valid for operations that write to the database:
1169
1040
- ` deleteMany() `
1170
1041
- ` findOneAndDelete() `
1171
1042
- ` findOneAndUpdate() `
1172
- - ` remove() `
1173
- - ` update() `
1174
1043
- ` updateOne() `
1175
1044
- ` updateMany() `
1176
1045
@@ -1240,11 +1109,9 @@ mquery().setOptions({ collection: coll, limit: 20 })
1240
1109
- [ sort] ( #sort ) *
1241
1110
- [ limit] ( #limit ) *
1242
1111
- [ skip] ( #skip ) *
1243
- - [ maxScan] ( #maxscan ) *
1244
1112
- [ maxTime] ( #maxtime ) *
1245
1113
- [ batchSize] ( #batchsize ) *
1246
1114
- [ comment] ( #comment ) *
1247
- - [ snapshot] ( #snapshot ) *
1248
1115
- [ hint] ( #hint ) *
1249
1116
- [ collection] ( #collection ) : the collection to query against
1250
1117
0 commit comments