mongoose 6.2.7 → 6.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +35 -26
- package/CHANGELOG.md +27 -0
- package/dist/browser.umd.js +71 -71
- package/lib/aggregate.js +36 -36
- package/lib/browser.js +4 -4
- package/lib/browserDocument.js +1 -0
- package/lib/connection.js +21 -21
- package/lib/cursor/AggregationCursor.js +2 -3
- package/lib/cursor/QueryCursor.js +3 -3
- package/lib/document.js +75 -47
- package/lib/error/index.js +2 -2
- package/lib/helpers/document/handleSpreadDoc.js +19 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/query/castFilterPath.js +0 -1
- package/lib/index.js +24 -26
- package/lib/model.js +141 -136
- package/lib/options/SchemaArrayOptions.js +2 -2
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDateOptions.js +9 -2
- package/lib/options/SchemaDocumentArrayOptions.js +3 -3
- package/lib/options/SchemaMapOptions.js +2 -2
- package/lib/options/SchemaNumberOptions.js +3 -3
- package/lib/options/SchemaObjectIdOptions.js +2 -2
- package/lib/options/SchemaStringOptions.js +1 -1
- package/lib/options/SchemaSubdocumentOptions.js +2 -2
- package/lib/options/SchemaTypeOptions.js +3 -3
- package/lib/query.js +253 -225
- package/lib/schema/SubdocumentPath.js +6 -3
- package/lib/schema/array.js +3 -2
- package/lib/schema/boolean.js +4 -4
- package/lib/schema/buffer.js +3 -3
- package/lib/schema/date.js +7 -7
- package/lib/schema/decimal128.js +2 -2
- package/lib/schema/documentarray.js +17 -10
- package/lib/schema/mixed.js +2 -2
- package/lib/schema/number.js +6 -6
- package/lib/schema/objectid.js +4 -4
- package/lib/schema/string.js +14 -14
- package/lib/schema.js +28 -28
- package/lib/schematype.js +78 -68
- package/lib/types/ArraySubdocument.js +1 -1
- package/lib/types/DocumentArray/methods/index.js +2 -2
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +14 -12
- package/lib/types/buffer.js +1 -1
- package/lib/types/decimal128.js +1 -1
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +2 -2
- package/lib/virtualtype.js +4 -3
- package/package.json +18 -17
- package/tools/repl.js +8 -8
- package/tools/sharded.js +3 -3
- package/types/connection.d.ts +116 -116
- package/types/document.d.ts +3 -0
- package/types/error.d.ts +2 -2
- package/types/index.d.ts +75 -67
- package/types/pipelinestage.d.ts +194 -194
- package/types/schemaoptions.d.ts +2 -2
package/lib/query.js
CHANGED
|
@@ -39,12 +39,37 @@ const utils = require('./utils');
|
|
|
39
39
|
const validOps = require('./helpers/query/validOps');
|
|
40
40
|
const wrapThunk = require('./helpers/query/wrapThunk');
|
|
41
41
|
|
|
42
|
+
const queryOptionMethods = new Set([
|
|
43
|
+
'allowDiskUse',
|
|
44
|
+
'batchSize',
|
|
45
|
+
'collation',
|
|
46
|
+
'comment',
|
|
47
|
+
'explain',
|
|
48
|
+
'hint',
|
|
49
|
+
'j',
|
|
50
|
+
'lean',
|
|
51
|
+
'limit',
|
|
52
|
+
'maxScan',
|
|
53
|
+
'maxTimeMS',
|
|
54
|
+
'maxscan',
|
|
55
|
+
'projection',
|
|
56
|
+
'read',
|
|
57
|
+
'select',
|
|
58
|
+
'skip',
|
|
59
|
+
'slice',
|
|
60
|
+
'sort',
|
|
61
|
+
'tailable',
|
|
62
|
+
'w',
|
|
63
|
+
'writeConcern',
|
|
64
|
+
'wtimeout'
|
|
65
|
+
]);
|
|
66
|
+
|
|
42
67
|
/**
|
|
43
68
|
* Query constructor used for building queries. You do not need
|
|
44
69
|
* to instantiate a `Query` directly. Instead use Model functions like
|
|
45
70
|
* [`Model.find()`](/docs/api.html#find_find).
|
|
46
71
|
*
|
|
47
|
-
* ####Example:
|
|
72
|
+
* #### Example:
|
|
48
73
|
*
|
|
49
74
|
* const query = MyModel.find(); // `query` is an instance of `Query`
|
|
50
75
|
* query.setOptions({ lean : true });
|
|
@@ -129,7 +154,9 @@ Query.base = mquery.prototype;
|
|
|
129
154
|
/**
|
|
130
155
|
* Flag to opt out of using `$geoWithin`.
|
|
131
156
|
*
|
|
132
|
-
*
|
|
157
|
+
* ```javascript
|
|
158
|
+
* mongoose.Query.use$geoWithin = false;
|
|
159
|
+
* ```
|
|
133
160
|
*
|
|
134
161
|
* MongoDB 2.4 deprecated the use of `$within`, replacing it with `$geoWithin`. Mongoose uses `$geoWithin` by default (which is 100% backward compatible with `$within`). If you are running an older version of MongoDB, set this flag to `false` so your `within()` queries continue to work.
|
|
135
162
|
*
|
|
@@ -146,7 +173,7 @@ Query.use$geoWithin = mquery.use$geoWithin;
|
|
|
146
173
|
/**
|
|
147
174
|
* Converts this query to a customized, reusable query constructor with all arguments and options retained.
|
|
148
175
|
*
|
|
149
|
-
* ####Example
|
|
176
|
+
* #### Example
|
|
150
177
|
*
|
|
151
178
|
* // Create a query for adventure movies and read from the primary
|
|
152
179
|
* // node in the replica-set unless it is down, in which case we'll
|
|
@@ -228,7 +255,7 @@ Query.prototype.toConstructor = function toConstructor() {
|
|
|
228
255
|
/**
|
|
229
256
|
* Make a copy of this query so you can re-execute it.
|
|
230
257
|
*
|
|
231
|
-
* ####Example:
|
|
258
|
+
* #### Example:
|
|
232
259
|
* const q = Book.findOne({ title: 'Casino Royale' });
|
|
233
260
|
* await q.exec();
|
|
234
261
|
* await q.exec(); // Throws an error because you can't execute a query twice
|
|
@@ -276,7 +303,7 @@ Query.prototype.clone = function clone() {
|
|
|
276
303
|
/**
|
|
277
304
|
* Specifies a javascript function or expression to pass to MongoDBs query system.
|
|
278
305
|
*
|
|
279
|
-
* ####Example
|
|
306
|
+
* #### Example
|
|
280
307
|
*
|
|
281
308
|
* query.$where('this.comments.length === 10 || this.name.length === 5')
|
|
282
309
|
*
|
|
@@ -286,7 +313,7 @@ Query.prototype.clone = function clone() {
|
|
|
286
313
|
* return this.comments.length === 10 || this.name.length === 5;
|
|
287
314
|
* })
|
|
288
315
|
*
|
|
289
|
-
* ####
|
|
316
|
+
* #### Note:
|
|
290
317
|
*
|
|
291
318
|
* Only use `$where` when you have a condition that cannot be met using other MongoDB operators like `$lt`.
|
|
292
319
|
* **Be sure to read about all of [its caveats](https://docs.mongodb.org/manual/reference/operator/where/) before using.**
|
|
@@ -304,7 +331,7 @@ Query.prototype.clone = function clone() {
|
|
|
304
331
|
/**
|
|
305
332
|
* Specifies a `path` for use with chaining.
|
|
306
333
|
*
|
|
307
|
-
* ####Example
|
|
334
|
+
* #### Example
|
|
308
335
|
*
|
|
309
336
|
* // instead of writing:
|
|
310
337
|
* User.find({age: {$gte: 21, $lte: 65}}, callback);
|
|
@@ -334,13 +361,13 @@ Query.prototype.clone = function clone() {
|
|
|
334
361
|
/**
|
|
335
362
|
* Specifies a `$slice` projection for an array.
|
|
336
363
|
*
|
|
337
|
-
* ####Example
|
|
364
|
+
* #### Example
|
|
338
365
|
*
|
|
339
|
-
* query.slice('comments', 5)
|
|
340
|
-
* query.slice('comments', -5)
|
|
341
|
-
* query.slice('comments', [10, 5])
|
|
342
|
-
* query.where('comments').slice(5)
|
|
343
|
-
* query.where('comments').slice([-10, 5])
|
|
366
|
+
* query.slice('comments', 5);
|
|
367
|
+
* query.slice('comments', -5);
|
|
368
|
+
* query.slice('comments', [10, 5]);
|
|
369
|
+
* query.where('comments').slice(5);
|
|
370
|
+
* query.where('comments').slice([-10, 5]);
|
|
344
371
|
*
|
|
345
372
|
* @method slice
|
|
346
373
|
* @memberOf Query
|
|
@@ -412,7 +439,7 @@ Query.prototype._validateOp = function() {
|
|
|
412
439
|
/**
|
|
413
440
|
* Specifies the complementary comparison value for paths specified with `where()`
|
|
414
441
|
*
|
|
415
|
-
* ####Example
|
|
442
|
+
* #### Example
|
|
416
443
|
*
|
|
417
444
|
* User.where('age').equals(49);
|
|
418
445
|
*
|
|
@@ -431,9 +458,9 @@ Query.prototype._validateOp = function() {
|
|
|
431
458
|
/**
|
|
432
459
|
* Specifies arguments for an `$or` condition.
|
|
433
460
|
*
|
|
434
|
-
* ####Example
|
|
461
|
+
* #### Example
|
|
435
462
|
*
|
|
436
|
-
* query.or([{ color: 'red' }, { status: 'emergency' }])
|
|
463
|
+
* query.or([{ color: 'red' }, { status: 'emergency' }]);
|
|
437
464
|
*
|
|
438
465
|
* @see $or https://docs.mongodb.org/manual/reference/operator/or/
|
|
439
466
|
* @method or
|
|
@@ -447,9 +474,9 @@ Query.prototype._validateOp = function() {
|
|
|
447
474
|
/**
|
|
448
475
|
* Specifies arguments for a `$nor` condition.
|
|
449
476
|
*
|
|
450
|
-
* ####Example
|
|
477
|
+
* #### Example
|
|
451
478
|
*
|
|
452
|
-
* query.nor([{ color: 'green' }, { status: 'ok' }])
|
|
479
|
+
* query.nor([{ color: 'green' }, { status: 'ok' }]);
|
|
453
480
|
*
|
|
454
481
|
* @see $nor https://docs.mongodb.org/manual/reference/operator/nor/
|
|
455
482
|
* @method nor
|
|
@@ -463,7 +490,7 @@ Query.prototype._validateOp = function() {
|
|
|
463
490
|
/**
|
|
464
491
|
* Specifies arguments for a `$and` condition.
|
|
465
492
|
*
|
|
466
|
-
* ####Example
|
|
493
|
+
* #### Example
|
|
467
494
|
*
|
|
468
495
|
* query.and([{ color: 'green' }, { status: 'ok' }])
|
|
469
496
|
*
|
|
@@ -481,12 +508,12 @@ Query.prototype._validateOp = function() {
|
|
|
481
508
|
*
|
|
482
509
|
* When called with one argument, the most recent path passed to `where()` is used.
|
|
483
510
|
*
|
|
484
|
-
* ####Example
|
|
511
|
+
* #### Example
|
|
485
512
|
*
|
|
486
|
-
* Thing.find().where('age').gt(21)
|
|
513
|
+
* Thing.find().where('age').gt(21);
|
|
487
514
|
*
|
|
488
515
|
* // or
|
|
489
|
-
* Thing.find().gt('age', 21)
|
|
516
|
+
* Thing.find().gt('age', 21);
|
|
490
517
|
*
|
|
491
518
|
* @method gt
|
|
492
519
|
* @memberOf Query
|
|
@@ -586,7 +613,7 @@ Query.prototype._validateOp = function() {
|
|
|
586
613
|
*
|
|
587
614
|
* When called with one argument, the most recent path passed to `where()` is used.
|
|
588
615
|
*
|
|
589
|
-
* ####Example:
|
|
616
|
+
* #### Example:
|
|
590
617
|
*
|
|
591
618
|
* MyModel.find().where('pets').all(['dog', 'cat', 'ferret']);
|
|
592
619
|
* // Equivalent:
|
|
@@ -606,7 +633,7 @@ Query.prototype._validateOp = function() {
|
|
|
606
633
|
*
|
|
607
634
|
* When called with one argument, the most recent path passed to `where()` is used.
|
|
608
635
|
*
|
|
609
|
-
* ####Example
|
|
636
|
+
* #### Example
|
|
610
637
|
*
|
|
611
638
|
* const docs = await MyModel.where('tags').size(0).exec();
|
|
612
639
|
* assert(Array.isArray(docs));
|
|
@@ -653,7 +680,7 @@ Query.prototype._validateOp = function() {
|
|
|
653
680
|
* Specifies a `$mod` condition, filters documents for documents whose
|
|
654
681
|
* `path` property is a number that is equal to `remainder` modulo `divisor`.
|
|
655
682
|
*
|
|
656
|
-
* ####Example
|
|
683
|
+
* #### Example
|
|
657
684
|
*
|
|
658
685
|
* // All find products whose inventory is odd
|
|
659
686
|
* Product.find().mod('inventory', [2, 1]);
|
|
@@ -699,7 +726,7 @@ Query.prototype.mod = function() {
|
|
|
699
726
|
/**
|
|
700
727
|
* Specifies an `$exists` condition
|
|
701
728
|
*
|
|
702
|
-
* ####Example
|
|
729
|
+
* #### Example
|
|
703
730
|
*
|
|
704
731
|
* // { name: { $exists: true }}
|
|
705
732
|
* Thing.where('name').exists()
|
|
@@ -723,7 +750,7 @@ Query.prototype.mod = function() {
|
|
|
723
750
|
/**
|
|
724
751
|
* Specifies an `$elemMatch` condition
|
|
725
752
|
*
|
|
726
|
-
* ####Example
|
|
753
|
+
* #### Example
|
|
727
754
|
*
|
|
728
755
|
* query.elemMatch('comment', { author: 'autobot', votes: {$gte: 5}})
|
|
729
756
|
*
|
|
@@ -752,7 +779,7 @@ Query.prototype.mod = function() {
|
|
|
752
779
|
/**
|
|
753
780
|
* Defines a `$within` or `$geoWithin` argument for geo-spatial queries.
|
|
754
781
|
*
|
|
755
|
-
* ####Example
|
|
782
|
+
* #### Example
|
|
756
783
|
*
|
|
757
784
|
* query.where(path).within().box()
|
|
758
785
|
* query.where(path).within().circle()
|
|
@@ -768,11 +795,11 @@ Query.prototype.mod = function() {
|
|
|
768
795
|
*
|
|
769
796
|
* **MUST** be used after `where()`.
|
|
770
797
|
*
|
|
771
|
-
* ####
|
|
798
|
+
* #### Note:
|
|
772
799
|
*
|
|
773
800
|
* As of Mongoose 3.7, `$geoWithin` is always used for queries. To change this behavior, see [Query.use$geoWithin](#query_Query-use%2524geoWithin).
|
|
774
801
|
*
|
|
775
|
-
* ####
|
|
802
|
+
* #### Note:
|
|
776
803
|
*
|
|
777
804
|
* In Mongoose 3.7, `within` changed from a getter to a function. If you need the old syntax, use [this](https://github.com/ebensing/mongoose-within).
|
|
778
805
|
*
|
|
@@ -791,11 +818,11 @@ Query.prototype.mod = function() {
|
|
|
791
818
|
/**
|
|
792
819
|
* Specifies the maximum number of documents the query will return.
|
|
793
820
|
*
|
|
794
|
-
* ####Example
|
|
821
|
+
* #### Example
|
|
795
822
|
*
|
|
796
|
-
* query.limit(20)
|
|
823
|
+
* query.limit(20);
|
|
797
824
|
*
|
|
798
|
-
* ####Note
|
|
825
|
+
* #### Note
|
|
799
826
|
*
|
|
800
827
|
* Cannot be used with `distinct()`
|
|
801
828
|
*
|
|
@@ -824,11 +851,11 @@ Query.prototype.limit = function limit(v) {
|
|
|
824
851
|
/**
|
|
825
852
|
* Specifies the number of documents to skip.
|
|
826
853
|
*
|
|
827
|
-
* ####Example
|
|
854
|
+
* #### Example
|
|
828
855
|
*
|
|
829
|
-
* query.skip(100).limit(20)
|
|
856
|
+
* query.skip(100).limit(20);
|
|
830
857
|
*
|
|
831
|
-
* ####Note
|
|
858
|
+
* #### Note
|
|
832
859
|
*
|
|
833
860
|
* Cannot be used with `distinct()`
|
|
834
861
|
*
|
|
@@ -858,11 +885,11 @@ Query.prototype.skip = function skip(v) {
|
|
|
858
885
|
/**
|
|
859
886
|
* Specifies the maxScan option.
|
|
860
887
|
*
|
|
861
|
-
* ####Example
|
|
888
|
+
* #### Example
|
|
862
889
|
*
|
|
863
|
-
* query.maxScan(100)
|
|
890
|
+
* query.maxScan(100);
|
|
864
891
|
*
|
|
865
|
-
* ####Note
|
|
892
|
+
* #### Note
|
|
866
893
|
*
|
|
867
894
|
* Cannot be used with `distinct()`
|
|
868
895
|
*
|
|
@@ -877,11 +904,11 @@ Query.prototype.skip = function skip(v) {
|
|
|
877
904
|
/**
|
|
878
905
|
* Specifies the batchSize option.
|
|
879
906
|
*
|
|
880
|
-
* ####Example
|
|
907
|
+
* #### Example
|
|
881
908
|
*
|
|
882
909
|
* query.batchSize(100)
|
|
883
910
|
*
|
|
884
|
-
* ####Note
|
|
911
|
+
* #### Note
|
|
885
912
|
*
|
|
886
913
|
* Cannot be used with `distinct()`
|
|
887
914
|
*
|
|
@@ -896,11 +923,11 @@ Query.prototype.skip = function skip(v) {
|
|
|
896
923
|
/**
|
|
897
924
|
* Specifies the `comment` option.
|
|
898
925
|
*
|
|
899
|
-
* ####Example
|
|
926
|
+
* #### Example
|
|
900
927
|
*
|
|
901
928
|
* query.comment('login query')
|
|
902
929
|
*
|
|
903
|
-
* ####Note
|
|
930
|
+
* #### Note
|
|
904
931
|
*
|
|
905
932
|
* Cannot be used with `distinct()`
|
|
906
933
|
*
|
|
@@ -915,13 +942,13 @@ Query.prototype.skip = function skip(v) {
|
|
|
915
942
|
/**
|
|
916
943
|
* Specifies this query as a `snapshot` query.
|
|
917
944
|
*
|
|
918
|
-
* ####Example
|
|
945
|
+
* #### Example
|
|
919
946
|
*
|
|
920
|
-
* query.snapshot() // true
|
|
921
|
-
* query.snapshot(true)
|
|
922
|
-
* query.snapshot(false)
|
|
947
|
+
* query.snapshot(); // true
|
|
948
|
+
* query.snapshot(true);
|
|
949
|
+
* query.snapshot(false);
|
|
923
950
|
*
|
|
924
|
-
* ####Note
|
|
951
|
+
* #### Note
|
|
925
952
|
*
|
|
926
953
|
* Cannot be used with `distinct()`
|
|
927
954
|
*
|
|
@@ -936,11 +963,11 @@ Query.prototype.skip = function skip(v) {
|
|
|
936
963
|
/**
|
|
937
964
|
* Sets query hints.
|
|
938
965
|
*
|
|
939
|
-
* ####Example
|
|
966
|
+
* #### Example
|
|
940
967
|
*
|
|
941
|
-
* query.hint({ indexA: 1, indexB: -1})
|
|
968
|
+
* query.hint({ indexA: 1, indexB: -1 });
|
|
942
969
|
*
|
|
943
|
-
* ####Note
|
|
970
|
+
* #### Note
|
|
944
971
|
*
|
|
945
972
|
* Cannot be used with `distinct()`
|
|
946
973
|
*
|
|
@@ -960,7 +987,7 @@ Query.prototype.skip = function skip(v) {
|
|
|
960
987
|
* Unlike `projection()`, the `select()` function modifies the current
|
|
961
988
|
* projection in place. This function overwrites the existing projection.
|
|
962
989
|
*
|
|
963
|
-
* ####Example:
|
|
990
|
+
* #### Example:
|
|
964
991
|
*
|
|
965
992
|
* const q = Model.find();
|
|
966
993
|
* q.projection(); // null
|
|
@@ -1003,7 +1030,7 @@ Query.prototype.projection = function(arg) {
|
|
|
1003
1030
|
* either list the fields to include (which excludes all others), or list the fields
|
|
1004
1031
|
* to exclude (which implies all other fields are included). The [`_id` field is the only exception because MongoDB includes it by default](https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/#suppress-id-field).
|
|
1005
1032
|
*
|
|
1006
|
-
* ####Example
|
|
1033
|
+
* #### Example
|
|
1007
1034
|
*
|
|
1008
1035
|
* // include a and b, exclude other fields
|
|
1009
1036
|
* query.select('a b');
|
|
@@ -1114,49 +1141,30 @@ Query.prototype.select = function select() {
|
|
|
1114
1141
|
throw new TypeError('Invalid select() argument. Must be string or object.');
|
|
1115
1142
|
};
|
|
1116
1143
|
|
|
1117
|
-
/**
|
|
1118
|
-
* _DEPRECATED_ Sets the slaveOk option.
|
|
1119
|
-
*
|
|
1120
|
-
* **Deprecated** in MongoDB 2.2 in favor of [read preferences](#query_Query-read).
|
|
1121
|
-
*
|
|
1122
|
-
* ####Example:
|
|
1123
|
-
*
|
|
1124
|
-
* query.slaveOk() // true
|
|
1125
|
-
* query.slaveOk(true)
|
|
1126
|
-
* query.slaveOk(false)
|
|
1127
|
-
*
|
|
1128
|
-
* @method slaveOk
|
|
1129
|
-
* @memberOf Query
|
|
1130
|
-
* @instance
|
|
1131
|
-
* @deprecated use read() preferences instead if on mongodb >= 2.2
|
|
1132
|
-
* @param {Boolean} v defaults to true
|
|
1133
|
-
* @see mongodb https://docs.mongodb.org/manual/applications/replication/#read-preference
|
|
1134
|
-
* @see slaveOk https://docs.mongodb.org/manual/reference/method/rs.slaveOk/
|
|
1135
|
-
* @see read() #query_Query-read
|
|
1136
|
-
* @return {Query} this
|
|
1137
|
-
* @api public
|
|
1138
|
-
*/
|
|
1139
|
-
|
|
1140
1144
|
/**
|
|
1141
1145
|
* Determines the MongoDB nodes from which to read.
|
|
1142
1146
|
*
|
|
1143
|
-
* ####Preferences:
|
|
1147
|
+
* #### Preferences:
|
|
1144
1148
|
*
|
|
1145
|
-
*
|
|
1146
|
-
*
|
|
1147
|
-
*
|
|
1148
|
-
*
|
|
1149
|
-
*
|
|
1149
|
+
* ```
|
|
1150
|
+
* primary - (default) Read from primary only. Operations will produce an error if primary is unavailable. Cannot be combined with tags.
|
|
1151
|
+
* secondary Read from secondary if available, otherwise error.
|
|
1152
|
+
* primaryPreferred Read from primary if available, otherwise a secondary.
|
|
1153
|
+
* secondaryPreferred Read from a secondary if available, otherwise read from the primary.
|
|
1154
|
+
* nearest All operations read from among the nearest candidates, but unlike other modes, this option will include both the primary and all secondaries in the random selection.
|
|
1155
|
+
* ```
|
|
1150
1156
|
*
|
|
1151
1157
|
* Aliases
|
|
1152
1158
|
*
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
*
|
|
1159
|
+
* ```
|
|
1160
|
+
* p primary
|
|
1161
|
+
* pp primaryPreferred
|
|
1162
|
+
* s secondary
|
|
1163
|
+
* sp secondaryPreferred
|
|
1164
|
+
* n nearest
|
|
1165
|
+
* ```
|
|
1158
1166
|
*
|
|
1159
|
-
* ####Example:
|
|
1167
|
+
* #### Example:
|
|
1160
1168
|
*
|
|
1161
1169
|
* new Query().read('primary')
|
|
1162
1170
|
* new Query().read('p') // same as primary
|
|
@@ -1235,7 +1243,7 @@ Query.prototype.toString = function toString() {
|
|
|
1235
1243
|
*
|
|
1236
1244
|
* Calling `session(null)` removes the session from this query.
|
|
1237
1245
|
*
|
|
1238
|
-
* ####Example:
|
|
1246
|
+
* #### Example:
|
|
1239
1247
|
*
|
|
1240
1248
|
* const s = await mongoose.startSession();
|
|
1241
1249
|
* await mongoose.model('Person').findOne({ name: 'Axl Rose' }).session(s);
|
|
@@ -1279,7 +1287,7 @@ Query.prototype.session = function session(v) {
|
|
|
1279
1287
|
*
|
|
1280
1288
|
* Defaults to the schema's [`writeConcern` option](/docs/guide.html#writeConcern)
|
|
1281
1289
|
*
|
|
1282
|
-
* ####Example:
|
|
1290
|
+
* #### Example:
|
|
1283
1291
|
*
|
|
1284
1292
|
* // The 'majority' option means the `deleteOne()` promise won't resolve
|
|
1285
1293
|
* // until the `deleteOne()` has propagated to the majority of the replica set
|
|
@@ -1322,7 +1330,7 @@ Query.prototype.writeConcern = function writeConcern(val) {
|
|
|
1322
1330
|
*
|
|
1323
1331
|
* Defaults to the schema's [`writeConcern.w` option](/docs/guide.html#writeConcern)
|
|
1324
1332
|
*
|
|
1325
|
-
* ####Example:
|
|
1333
|
+
* #### Example:
|
|
1326
1334
|
*
|
|
1327
1335
|
* // The 'majority' option means the `deleteOne()` promise won't resolve
|
|
1328
1336
|
* // until the `deleteOne()` has propagated to the majority of the replica set
|
|
@@ -1368,7 +1376,7 @@ Query.prototype.w = function w(val) {
|
|
|
1368
1376
|
*
|
|
1369
1377
|
* Defaults to the schema's [`writeConcern.j` option](/docs/guide.html#writeConcern)
|
|
1370
1378
|
*
|
|
1371
|
-
* ####Example:
|
|
1379
|
+
* #### Example:
|
|
1372
1380
|
*
|
|
1373
1381
|
* await mongoose.model('Person').deleteOne({ name: 'Ned Stark' }).j(true);
|
|
1374
1382
|
*
|
|
@@ -1412,7 +1420,7 @@ Query.prototype.j = function j(val) {
|
|
|
1412
1420
|
*
|
|
1413
1421
|
* Defaults to the schema's [`writeConcern.wtimeout` option](/docs/guide.html#writeConcern)
|
|
1414
1422
|
*
|
|
1415
|
-
* ####Example:
|
|
1423
|
+
* #### Example:
|
|
1416
1424
|
*
|
|
1417
1425
|
* // The `deleteOne()` promise won't resolve until this `deleteOne()` has
|
|
1418
1426
|
* // propagated to at least `w = 2` members of the replica set. If it takes
|
|
@@ -1446,7 +1454,7 @@ Query.prototype.wtimeout = function wtimeout(ms) {
|
|
|
1446
1454
|
/**
|
|
1447
1455
|
* Sets the readConcern option for the query.
|
|
1448
1456
|
*
|
|
1449
|
-
* ####Example:
|
|
1457
|
+
* #### Example:
|
|
1450
1458
|
*
|
|
1451
1459
|
* new Query().readConcern('local')
|
|
1452
1460
|
* new Query().readConcern('l') // same as local
|
|
@@ -1464,21 +1472,25 @@ Query.prototype.wtimeout = function wtimeout(ms) {
|
|
|
1464
1472
|
* new Query().readConcern('s') // same as snapshot
|
|
1465
1473
|
*
|
|
1466
1474
|
*
|
|
1467
|
-
* ####Read Concern Level:
|
|
1475
|
+
* #### Read Concern Level:
|
|
1468
1476
|
*
|
|
1469
|
-
*
|
|
1470
|
-
*
|
|
1471
|
-
*
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1477
|
+
* ```
|
|
1478
|
+
* local MongoDB 3.2+ The query returns from the instance with no guarantee guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
|
|
1479
|
+
* available MongoDB 3.6+ The query returns from the instance with no guarantee guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
|
|
1480
|
+
* majority MongoDB 3.2+ The query returns the data that has been acknowledged by a majority of the replica set members. The documents returned by the read operation are durable, even in the event of failure.
|
|
1481
|
+
* linearizable MongoDB 3.4+ The query returns data that reflects all successful majority-acknowledged writes that completed prior to the start of the read operation. The query may wait for concurrently executing writes to propagate to a majority of replica set members before returning results.
|
|
1482
|
+
* snapshot MongoDB 4.0+ Only available for operations within multi-document transactions. Upon transaction commit with write concern "majority", the transaction operations are guaranteed to have read from a snapshot of majority-committed data.
|
|
1483
|
+
* ```
|
|
1474
1484
|
*
|
|
1475
1485
|
* Aliases
|
|
1476
1486
|
*
|
|
1477
|
-
*
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1487
|
+
* ```
|
|
1488
|
+
* l local
|
|
1489
|
+
* a available
|
|
1490
|
+
* m majority
|
|
1491
|
+
* lz linearizable
|
|
1492
|
+
* s snapshot
|
|
1493
|
+
* ```
|
|
1482
1494
|
*
|
|
1483
1495
|
* Read more about how to use read concern [here](https://docs.mongodb.com/manual/reference/read-concern/).
|
|
1484
1496
|
*
|
|
@@ -1493,11 +1505,11 @@ Query.prototype.wtimeout = function wtimeout(ms) {
|
|
|
1493
1505
|
/**
|
|
1494
1506
|
* Gets query options.
|
|
1495
1507
|
*
|
|
1496
|
-
* ####Example:
|
|
1508
|
+
* #### Example:
|
|
1497
1509
|
*
|
|
1498
1510
|
* const query = new Query();
|
|
1499
1511
|
* query.limit(10);
|
|
1500
|
-
* query.setOptions({ maxTimeMS: 1000 })
|
|
1512
|
+
* query.setOptions({ maxTimeMS: 1000 });
|
|
1501
1513
|
* query.getOptions(); // { limit: 10, maxTimeMS: 1000 }
|
|
1502
1514
|
*
|
|
1503
1515
|
* @return {Object} the options
|
|
@@ -1511,7 +1523,7 @@ Query.prototype.getOptions = function() {
|
|
|
1511
1523
|
/**
|
|
1512
1524
|
* Sets query options. Some options only make sense for certain operations.
|
|
1513
1525
|
*
|
|
1514
|
-
* ####Options:
|
|
1526
|
+
* #### Options:
|
|
1515
1527
|
*
|
|
1516
1528
|
* The following options are only for `find()`:
|
|
1517
1529
|
*
|
|
@@ -1630,7 +1642,19 @@ Query.prototype.setOptions = function(options, overwrite) {
|
|
|
1630
1642
|
}
|
|
1631
1643
|
}
|
|
1632
1644
|
|
|
1633
|
-
|
|
1645
|
+
// set arbitrary options
|
|
1646
|
+
for (const key of Object.keys(options)) {
|
|
1647
|
+
if (queryOptionMethods.has(key)) {
|
|
1648
|
+
const args = Array.isArray(options[key]) ?
|
|
1649
|
+
options[key] :
|
|
1650
|
+
[options[key]];
|
|
1651
|
+
this[key].apply(this, args);
|
|
1652
|
+
} else {
|
|
1653
|
+
this.options[key] = options[key];
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
return this;
|
|
1634
1658
|
};
|
|
1635
1659
|
|
|
1636
1660
|
/**
|
|
@@ -1641,7 +1665,7 @@ Query.prototype.setOptions = function(options, overwrite) {
|
|
|
1641
1665
|
*
|
|
1642
1666
|
* Calling `query.explain(v)` is equivalent to `query.setOptions({ explain: v })`
|
|
1643
1667
|
*
|
|
1644
|
-
* ####Example:
|
|
1668
|
+
* #### Example:
|
|
1645
1669
|
*
|
|
1646
1670
|
* const query = new Query();
|
|
1647
1671
|
* const res = await query.find({ a: 1 }).explain('queryPlanner');
|
|
@@ -1673,7 +1697,7 @@ Query.prototype.explain = function(verbose) {
|
|
|
1673
1697
|
*
|
|
1674
1698
|
* Calling `query.allowDiskUse(v)` is equivalent to `query.setOptions({ allowDiskUse: v })`
|
|
1675
1699
|
*
|
|
1676
|
-
* ####Example:
|
|
1700
|
+
* #### Example:
|
|
1677
1701
|
*
|
|
1678
1702
|
* await query.find().sort({ name: 1 }).allowDiskUse(true);
|
|
1679
1703
|
* // Equivalent:
|
|
@@ -1702,7 +1726,7 @@ Query.prototype.allowDiskUse = function(v) {
|
|
|
1702
1726
|
*
|
|
1703
1727
|
* Calling `query.maxTimeMS(v)` is equivalent to `query.setOptions({ maxTimeMS: v })`
|
|
1704
1728
|
*
|
|
1705
|
-
* ####Example:
|
|
1729
|
+
* #### Example:
|
|
1706
1730
|
*
|
|
1707
1731
|
* const query = new Query();
|
|
1708
1732
|
* // Throws an error 'operation exceeded time limit' as long as there's
|
|
@@ -1722,7 +1746,7 @@ Query.prototype.maxTimeMS = function(ms) {
|
|
|
1722
1746
|
/**
|
|
1723
1747
|
* Returns the current query filter (also known as conditions) as a [POJO](https://masteringjs.io/tutorials/fundamentals/pojo).
|
|
1724
1748
|
*
|
|
1725
|
-
* ####Example:
|
|
1749
|
+
* #### Example:
|
|
1726
1750
|
*
|
|
1727
1751
|
* const query = new Query();
|
|
1728
1752
|
* query.find({ a: 1 }).where('b').gt(2);
|
|
@@ -1742,7 +1766,7 @@ Query.prototype.getFilter = function() {
|
|
|
1742
1766
|
* You should use `getFilter()` instead of `getQuery()` where possible. `getQuery()`
|
|
1743
1767
|
* will likely be deprecated in a future release.
|
|
1744
1768
|
*
|
|
1745
|
-
* ####Example:
|
|
1769
|
+
* #### Example:
|
|
1746
1770
|
*
|
|
1747
1771
|
* const query = new Query();
|
|
1748
1772
|
* query.find({ a: 1 }).where('b').gt(2);
|
|
@@ -1759,7 +1783,7 @@ Query.prototype.getQuery = function() {
|
|
|
1759
1783
|
/**
|
|
1760
1784
|
* Sets the query conditions to the provided JSON object.
|
|
1761
1785
|
*
|
|
1762
|
-
* ####Example:
|
|
1786
|
+
* #### Example:
|
|
1763
1787
|
*
|
|
1764
1788
|
* const query = new Query();
|
|
1765
1789
|
* query.find({ a: 1 })
|
|
@@ -1778,7 +1802,7 @@ Query.prototype.setQuery = function(val) {
|
|
|
1778
1802
|
/**
|
|
1779
1803
|
* Returns the current update operations as a JSON object.
|
|
1780
1804
|
*
|
|
1781
|
-
* ####Example:
|
|
1805
|
+
* #### Example:
|
|
1782
1806
|
*
|
|
1783
1807
|
* const query = new Query();
|
|
1784
1808
|
* query.update({}, { $set: { a: 5 } });
|
|
@@ -1795,7 +1819,7 @@ Query.prototype.getUpdate = function() {
|
|
|
1795
1819
|
/**
|
|
1796
1820
|
* Sets the current update operation to new value.
|
|
1797
1821
|
*
|
|
1798
|
-
* ####Example:
|
|
1822
|
+
* #### Example:
|
|
1799
1823
|
*
|
|
1800
1824
|
* const query = new Query();
|
|
1801
1825
|
* query.update({}, { $set: { a: 5 } });
|
|
@@ -1948,7 +1972,7 @@ Query.prototype._optionsForExec = function(model) {
|
|
|
1948
1972
|
* javascript objects, not [Mongoose Documents](/api/document.html). They have no
|
|
1949
1973
|
* `save` method, getters/setters, virtuals, or other Mongoose features.
|
|
1950
1974
|
*
|
|
1951
|
-
* ####Example:
|
|
1975
|
+
* #### Example:
|
|
1952
1976
|
*
|
|
1953
1977
|
* new Query().lean() // true
|
|
1954
1978
|
* new Query().lean(true)
|
|
@@ -1983,7 +2007,7 @@ Query.prototype.lean = function(v) {
|
|
|
1983
2007
|
* This is useful for query middleware so you can add an update regardless
|
|
1984
2008
|
* of whether you use `updateOne()`, `updateMany()`, `findOneAndUpdate()`, etc.
|
|
1985
2009
|
*
|
|
1986
|
-
* ####Example:
|
|
2010
|
+
* #### Example:
|
|
1987
2011
|
*
|
|
1988
2012
|
* // Updates `{ $set: { updatedAt: new Date() } }`
|
|
1989
2013
|
* new Query().updateOne({}, {}).set('updatedAt', new Date());
|
|
@@ -2015,7 +2039,7 @@ Query.prototype.set = function(path, val) {
|
|
|
2015
2039
|
* Useful for writing getters/setters that can work with both update operations
|
|
2016
2040
|
* and `save()`.
|
|
2017
2041
|
*
|
|
2018
|
-
* ####Example:
|
|
2042
|
+
* #### Example:
|
|
2019
2043
|
*
|
|
2020
2044
|
* const query = Model.updateOne({}, { $set: { name: 'Jean-Luc Picard' } });
|
|
2021
2045
|
* query.get('name'); // 'Jean-Luc Picard'
|
|
@@ -2049,7 +2073,7 @@ Query.prototype.get = function get(path) {
|
|
|
2049
2073
|
* Gets/sets the error flag on this query. If this flag is not null or
|
|
2050
2074
|
* undefined, the `exec()` promise will reject without executing.
|
|
2051
2075
|
*
|
|
2052
|
-
* ####Example:
|
|
2076
|
+
* #### Example:
|
|
2053
2077
|
*
|
|
2054
2078
|
* Query().error(); // Get current error value
|
|
2055
2079
|
* Query().error(null); // Unset the current error
|
|
@@ -2063,7 +2087,7 @@ Query.prototype.get = function get(path) {
|
|
|
2063
2087
|
* Note that query casting runs **after** hooks, so cast errors will override
|
|
2064
2088
|
* custom errors.
|
|
2065
2089
|
*
|
|
2066
|
-
* ####Example:
|
|
2090
|
+
* #### Example:
|
|
2067
2091
|
* const TestSchema = new Schema({ num: Number });
|
|
2068
2092
|
* const TestModel = db.model('Test', TestSchema);
|
|
2069
2093
|
* TestModel.find({ num: 'not a number' }).error(new Error('woops')).exec(function(error) {
|
|
@@ -2250,7 +2274,7 @@ Query.prototype._find = wrapThunk(function(callback) {
|
|
|
2250
2274
|
* If there are too many documents in the result to fit in memory, use
|
|
2251
2275
|
* [`Query.prototype.cursor()`](api.html#query_Query-cursor)
|
|
2252
2276
|
*
|
|
2253
|
-
* ####Example
|
|
2277
|
+
* #### Example
|
|
2254
2278
|
*
|
|
2255
2279
|
* // Using async/await
|
|
2256
2280
|
* const arr = await Movie.find({ year: { $gte: 1980, $lte: 1989 } });
|
|
@@ -2456,7 +2480,7 @@ Query.prototype._findOne = wrapThunk(function(callback) {
|
|
|
2456
2480
|
*
|
|
2457
2481
|
* - `findOne()`
|
|
2458
2482
|
*
|
|
2459
|
-
* ####Example
|
|
2483
|
+
* #### Example
|
|
2460
2484
|
*
|
|
2461
2485
|
* const query = Kitten.where({ color: 'white' });
|
|
2462
2486
|
* query.findOne(function (err, kitten) {
|
|
@@ -2607,7 +2631,7 @@ Query.prototype._estimatedDocumentCount = wrapThunk(function(callback) {
|
|
|
2607
2631
|
*
|
|
2608
2632
|
* - `count()`
|
|
2609
2633
|
*
|
|
2610
|
-
* ####Example:
|
|
2634
|
+
* #### Example:
|
|
2611
2635
|
*
|
|
2612
2636
|
* const countQuery = model.where({ 'color': 'black' }).count();
|
|
2613
2637
|
*
|
|
@@ -2664,7 +2688,7 @@ Query.prototype.count = function(filter, callback) {
|
|
|
2664
2688
|
*
|
|
2665
2689
|
* - `estimatedDocumentCount()`
|
|
2666
2690
|
*
|
|
2667
|
-
* ####Example:
|
|
2691
|
+
* #### Example:
|
|
2668
2692
|
*
|
|
2669
2693
|
* await Model.find().estimatedDocumentCount();
|
|
2670
2694
|
*
|
|
@@ -2710,7 +2734,7 @@ Query.prototype.estimatedDocumentCount = function(options, callback) {
|
|
|
2710
2734
|
*
|
|
2711
2735
|
* - `countDocuments()`
|
|
2712
2736
|
*
|
|
2713
|
-
* ####Example:
|
|
2737
|
+
* #### Example:
|
|
2714
2738
|
*
|
|
2715
2739
|
* const countQuery = model.where({ 'color': 'black' }).countDocuments();
|
|
2716
2740
|
*
|
|
@@ -2804,7 +2828,7 @@ Query.prototype.__distinct = wrapThunk(function __distinct(callback) {
|
|
|
2804
2828
|
*
|
|
2805
2829
|
* This function does not trigger any middleware.
|
|
2806
2830
|
*
|
|
2807
|
-
* ####Example
|
|
2831
|
+
* #### Example
|
|
2808
2832
|
*
|
|
2809
2833
|
* distinct(field, conditions, callback)
|
|
2810
2834
|
* distinct(field, conditions)
|
|
@@ -2865,7 +2889,7 @@ Query.prototype.distinct = function(field, conditions, callback) {
|
|
|
2865
2889
|
* sort order of each path is ascending unless the path name is prefixed with `-`
|
|
2866
2890
|
* which will be treated as descending.
|
|
2867
2891
|
*
|
|
2868
|
-
* ####Example
|
|
2892
|
+
* #### Example
|
|
2869
2893
|
*
|
|
2870
2894
|
* // sort by "field" ascending and "test" descending
|
|
2871
2895
|
* query.sort({ field: 'asc', test: -1 });
|
|
@@ -2873,7 +2897,7 @@ Query.prototype.distinct = function(field, conditions, callback) {
|
|
|
2873
2897
|
* // equivalent
|
|
2874
2898
|
* query.sort('field -test');
|
|
2875
2899
|
*
|
|
2876
|
-
* ####Note
|
|
2900
|
+
* #### Note
|
|
2877
2901
|
*
|
|
2878
2902
|
* Cannot be used with `distinct()`
|
|
2879
2903
|
*
|
|
@@ -2898,7 +2922,7 @@ Query.prototype.sort = function(arg) {
|
|
|
2898
2922
|
*
|
|
2899
2923
|
* This function does not trigger any middleware
|
|
2900
2924
|
*
|
|
2901
|
-
* ####Example
|
|
2925
|
+
* #### Example
|
|
2902
2926
|
*
|
|
2903
2927
|
* Character.remove({ name: /Stark/ }, callback);
|
|
2904
2928
|
*
|
|
@@ -2910,13 +2934,13 @@ Query.prototype.sort = function(arg) {
|
|
|
2910
2934
|
* - `deletedCount`: the number of documents deleted
|
|
2911
2935
|
* - `n`: the number of documents deleted. Equal to `deletedCount`.
|
|
2912
2936
|
*
|
|
2913
|
-
* ####Example
|
|
2937
|
+
* #### Example
|
|
2914
2938
|
*
|
|
2915
2939
|
* const res = await Character.remove({ name: /Stark/ });
|
|
2916
2940
|
* // Number of docs deleted
|
|
2917
2941
|
* res.deletedCount;
|
|
2918
2942
|
*
|
|
2919
|
-
* ####Note
|
|
2943
|
+
* #### Note
|
|
2920
2944
|
*
|
|
2921
2945
|
* Calling `remove()` creates a [Mongoose query](./queries.html), and a query
|
|
2922
2946
|
* does not execute until you either pass a callback, call [`Query#then()`](#query_Query-then),
|
|
@@ -2990,7 +3014,7 @@ Query.prototype._remove = wrapThunk(function(callback) {
|
|
|
2990
3014
|
*
|
|
2991
3015
|
* This function triggers `deleteOne` middleware.
|
|
2992
3016
|
*
|
|
2993
|
-
* ####Example
|
|
3017
|
+
* #### Example
|
|
2994
3018
|
*
|
|
2995
3019
|
* await Character.deleteOne({ name: 'Eddard Stark' });
|
|
2996
3020
|
*
|
|
@@ -3005,7 +3029,7 @@ Query.prototype._remove = wrapThunk(function(callback) {
|
|
|
3005
3029
|
* - `deletedCount`: the number of documents deleted
|
|
3006
3030
|
* - `n`: the number of documents deleted. Equal to `deletedCount`.
|
|
3007
3031
|
*
|
|
3008
|
-
* ####Example
|
|
3032
|
+
* #### Example
|
|
3009
3033
|
*
|
|
3010
3034
|
* const res = await Character.deleteOne({ name: 'Eddard Stark' });
|
|
3011
3035
|
* // `1` if MongoDB deleted a doc, `0` if no docs matched the filter `{ name: ... }`
|
|
@@ -3076,7 +3100,7 @@ Query.prototype._deleteOne = wrapThunk(function(callback) {
|
|
|
3076
3100
|
*
|
|
3077
3101
|
* This function triggers `deleteMany` middleware.
|
|
3078
3102
|
*
|
|
3079
|
-
* ####Example
|
|
3103
|
+
* #### Example
|
|
3080
3104
|
*
|
|
3081
3105
|
* await Character.deleteMany({ name: /Stark/, age: { $gte: 18 } });
|
|
3082
3106
|
*
|
|
@@ -3091,7 +3115,7 @@ Query.prototype._deleteOne = wrapThunk(function(callback) {
|
|
|
3091
3115
|
* - `deletedCount`: the number of documents deleted
|
|
3092
3116
|
* - `n`: the number of documents deleted. Equal to `deletedCount`.
|
|
3093
3117
|
*
|
|
3094
|
-
* ####Example
|
|
3118
|
+
* #### Example
|
|
3095
3119
|
*
|
|
3096
3120
|
* const res = await Character.deleteMany({ name: /Stark/, age: { $gte: 18 } });
|
|
3097
3121
|
* // `0` if no docs matched the filter, number of docs deleted otherwise
|
|
@@ -3226,7 +3250,7 @@ function prepareDiscriminatorCriteria(query) {
|
|
|
3226
3250
|
*
|
|
3227
3251
|
* - `findOneAndUpdate()`
|
|
3228
3252
|
*
|
|
3229
|
-
* ####Available options
|
|
3253
|
+
* #### Available options
|
|
3230
3254
|
*
|
|
3231
3255
|
* - `new`: bool - if true, return the modified document rather than the original. defaults to false (changed in 4.0)
|
|
3232
3256
|
* - `upsert`: bool - creates the object if it doesn't exist. defaults to false.
|
|
@@ -3237,13 +3261,13 @@ function prepareDiscriminatorCriteria(query) {
|
|
|
3237
3261
|
* - `setDefaultsOnInsert`: `true` by default. If `setDefaultsOnInsert` and `upsert` are true, mongoose will apply the [defaults](https://mongoosejs.com/docs/defaults.html) specified in the model's schema if a new document is created.
|
|
3238
3262
|
* - `rawResult`: if true, returns the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.3/interfaces/ModifyResult.html)
|
|
3239
3263
|
*
|
|
3240
|
-
* ####Callback Signature
|
|
3264
|
+
* #### Callback Signature
|
|
3241
3265
|
* function(error, doc) {
|
|
3242
3266
|
* // error: any errors that occurred
|
|
3243
3267
|
* // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
|
|
3244
3268
|
* }
|
|
3245
3269
|
*
|
|
3246
|
-
* ####Examples
|
|
3270
|
+
* #### Examples
|
|
3247
3271
|
*
|
|
3248
3272
|
* query.findOneAndUpdate(conditions, update, options, callback) // executes
|
|
3249
3273
|
* query.findOneAndUpdate(conditions, update, options) // returns Query
|
|
@@ -3373,19 +3397,19 @@ Query.prototype._findOneAndUpdate = wrapThunk(function(callback) {
|
|
|
3373
3397
|
*
|
|
3374
3398
|
* - `findOneAndRemove()`
|
|
3375
3399
|
*
|
|
3376
|
-
* ####Available options
|
|
3400
|
+
* #### Available options
|
|
3377
3401
|
*
|
|
3378
3402
|
* - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
|
|
3379
3403
|
* - `maxTimeMS`: puts a time limit on the query - requires mongodb >= 2.6.0
|
|
3380
3404
|
* - `rawResult`: if true, resolves to the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.3/interfaces/ModifyResult.html)
|
|
3381
3405
|
*
|
|
3382
|
-
* ####Callback Signature
|
|
3406
|
+
* #### Callback Signature
|
|
3383
3407
|
* function(error, doc) {
|
|
3384
3408
|
* // error: any errors that occurred
|
|
3385
3409
|
* // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
|
|
3386
3410
|
* }
|
|
3387
3411
|
*
|
|
3388
|
-
* ####Examples
|
|
3412
|
+
* #### Examples
|
|
3389
3413
|
*
|
|
3390
3414
|
* A.where().findOneAndRemove(conditions, options, callback) // executes
|
|
3391
3415
|
* A.where().findOneAndRemove(conditions, options) // return Query
|
|
@@ -3460,19 +3484,19 @@ Query.prototype.findOneAndRemove = function(conditions, options, callback) {
|
|
|
3460
3484
|
* this distinction is purely pedantic. You should use `findOneAndDelete()`
|
|
3461
3485
|
* unless you have a good reason not to.
|
|
3462
3486
|
*
|
|
3463
|
-
* ####Available options
|
|
3487
|
+
* #### Available options
|
|
3464
3488
|
*
|
|
3465
3489
|
* - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
|
|
3466
3490
|
* - `maxTimeMS`: puts a time limit on the query - requires mongodb >= 2.6.0
|
|
3467
3491
|
* - `rawResult`: if true, resolves to the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.3/interfaces/ModifyResult.html)
|
|
3468
3492
|
*
|
|
3469
|
-
* ####Callback Signature
|
|
3493
|
+
* #### Callback Signature
|
|
3470
3494
|
* function(error, doc) {
|
|
3471
3495
|
* // error: any errors that occurred
|
|
3472
3496
|
* // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
|
|
3473
3497
|
* }
|
|
3474
3498
|
*
|
|
3475
|
-
* ####Examples
|
|
3499
|
+
* #### Examples
|
|
3476
3500
|
*
|
|
3477
3501
|
* A.where().findOneAndDelete(conditions, options, callback) // executes
|
|
3478
3502
|
* A.where().findOneAndDelete(conditions, options) // return Query
|
|
@@ -3579,19 +3603,19 @@ Query.prototype._findOneAndDelete = wrapThunk(function(callback) {
|
|
|
3579
3603
|
*
|
|
3580
3604
|
* - `findOneAndReplace()`
|
|
3581
3605
|
*
|
|
3582
|
-
* ####Available options
|
|
3606
|
+
* #### Available options
|
|
3583
3607
|
*
|
|
3584
3608
|
* - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
|
|
3585
3609
|
* - `maxTimeMS`: puts a time limit on the query - requires mongodb >= 2.6.0
|
|
3586
3610
|
* - `rawResult`: if true, resolves to the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.3/interfaces/ModifyResult.html)
|
|
3587
3611
|
*
|
|
3588
|
-
* ####Callback Signature
|
|
3612
|
+
* #### Callback Signature
|
|
3589
3613
|
* function(error, doc) {
|
|
3590
3614
|
* // error: any errors that occurred
|
|
3591
3615
|
* // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
|
|
3592
3616
|
* }
|
|
3593
3617
|
*
|
|
3594
|
-
* ####Examples
|
|
3618
|
+
* #### Examples
|
|
3595
3619
|
*
|
|
3596
3620
|
* A.where().findOneAndReplace(filter, replacement, options, callback); // executes
|
|
3597
3621
|
* A.where().findOneAndReplace(filter, replacement, options); // return Query
|
|
@@ -4156,15 +4180,15 @@ Query.prototype._replaceOne = wrapThunk(function(callback) {
|
|
|
4156
4180
|
*
|
|
4157
4181
|
* - `update()`
|
|
4158
4182
|
*
|
|
4159
|
-
* ####Example
|
|
4183
|
+
* #### Example
|
|
4160
4184
|
*
|
|
4161
|
-
* Model.where({ _id: id }).update({ title: 'words' })
|
|
4185
|
+
* Model.where({ _id: id }).update({ title: 'words' });
|
|
4162
4186
|
*
|
|
4163
4187
|
* // becomes
|
|
4164
4188
|
*
|
|
4165
|
-
* Model.where({ _id: id }).update({ $set: { title: 'words' }})
|
|
4189
|
+
* Model.where({ _id: id }).update({ $set: { title: 'words' }});
|
|
4166
4190
|
*
|
|
4167
|
-
* ####Valid options:
|
|
4191
|
+
* #### Valid options:
|
|
4168
4192
|
*
|
|
4169
4193
|
* - `upsert` (boolean) whether to create the doc if it doesn't match (false)
|
|
4170
4194
|
* - `multi` (boolean) whether multiple documents should be updated (false)
|
|
@@ -4174,47 +4198,51 @@ Query.prototype._replaceOne = wrapThunk(function(callback) {
|
|
|
4174
4198
|
* - `read`
|
|
4175
4199
|
* - `writeConcern`
|
|
4176
4200
|
*
|
|
4177
|
-
* ####Note
|
|
4201
|
+
* #### Note
|
|
4178
4202
|
*
|
|
4179
4203
|
* Passing an empty object `{}` as the doc will result in a no-op. The update operation will be ignored and the callback executed without sending the command to MongoDB.
|
|
4180
4204
|
*
|
|
4181
|
-
* ####Note
|
|
4205
|
+
* #### Note
|
|
4182
4206
|
*
|
|
4183
4207
|
* The operation is only executed when a callback is passed. To force execution without a callback, we must first call update() and then execute it by using the `exec()` method.
|
|
4184
4208
|
*
|
|
4185
|
-
*
|
|
4186
|
-
*
|
|
4209
|
+
* ```javascript
|
|
4210
|
+
* const q = Model.where({ _id: id });
|
|
4211
|
+
* q.update({ $set: { name: 'bob' }}).update(); // not executed
|
|
4187
4212
|
*
|
|
4188
|
-
*
|
|
4213
|
+
* q.update({ $set: { name: 'bob' }}).exec(); // executed
|
|
4189
4214
|
*
|
|
4190
|
-
*
|
|
4191
|
-
*
|
|
4192
|
-
*
|
|
4215
|
+
* // keys that are not [atomic](https://docs.mongodb.com/manual/tutorial/model-data-for-atomic-operations/#pattern) ops become `$set`.
|
|
4216
|
+
* // this executes the same command as the previous example.
|
|
4217
|
+
* q.update({ name: 'bob' }).exec();
|
|
4193
4218
|
*
|
|
4194
|
-
*
|
|
4195
|
-
*
|
|
4196
|
-
*
|
|
4219
|
+
* // multi updates
|
|
4220
|
+
* Model.where()
|
|
4221
|
+
* .update({ name: /^match/ }, { $set: { arr: [] }}, { multi: true }, callback)
|
|
4197
4222
|
*
|
|
4198
|
-
*
|
|
4199
|
-
*
|
|
4200
|
-
*
|
|
4201
|
-
*
|
|
4223
|
+
* // more multi updates
|
|
4224
|
+
* Model.where()
|
|
4225
|
+
* .setOptions({ multi: true })
|
|
4226
|
+
* .update({ $set: { arr: [] }}, callback)
|
|
4202
4227
|
*
|
|
4203
|
-
*
|
|
4204
|
-
*
|
|
4205
|
-
*
|
|
4228
|
+
* // single update by default
|
|
4229
|
+
* Model.where({ email: 'address@example.com' })
|
|
4230
|
+
* .update({ $inc: { counter: 1 }}, callback)
|
|
4231
|
+
* ```
|
|
4206
4232
|
*
|
|
4207
4233
|
* API summary
|
|
4208
4234
|
*
|
|
4209
|
-
*
|
|
4210
|
-
*
|
|
4211
|
-
*
|
|
4212
|
-
*
|
|
4213
|
-
*
|
|
4214
|
-
*
|
|
4215
|
-
*
|
|
4216
|
-
*
|
|
4217
|
-
*
|
|
4235
|
+
* ```javascript
|
|
4236
|
+
* update(filter, doc, options, cb); // executes
|
|
4237
|
+
* update(filter, doc, options);
|
|
4238
|
+
* update(filter, doc, cb); // executes
|
|
4239
|
+
* update(filter, doc);
|
|
4240
|
+
* update(doc, cb); // executes
|
|
4241
|
+
* update(doc);
|
|
4242
|
+
* update(cb); // executes
|
|
4243
|
+
* update(true); // executes
|
|
4244
|
+
* update();
|
|
4245
|
+
* ```
|
|
4218
4246
|
*
|
|
4219
4247
|
* @param {Object} [filter]
|
|
4220
4248
|
* @param {Object} [doc] the update command
|
|
@@ -4271,7 +4299,7 @@ Query.prototype.update = function(conditions, doc, options, callback) {
|
|
|
4271
4299
|
* **Note** updateMany will _not_ fire update middleware. Use `pre('updateMany')`
|
|
4272
4300
|
* and `post('updateMany')` instead.
|
|
4273
4301
|
*
|
|
4274
|
-
* ####Example:
|
|
4302
|
+
* #### Example:
|
|
4275
4303
|
* const res = await Person.updateMany({ name: /Stark$/ }, { isDeleted: true });
|
|
4276
4304
|
* res.n; // Number of documents matched
|
|
4277
4305
|
* res.nModified; // Number of documents modified
|
|
@@ -4336,7 +4364,7 @@ Query.prototype.updateMany = function(conditions, doc, options, callback) {
|
|
|
4336
4364
|
* **Note** updateOne will _not_ fire update middleware. Use `pre('updateOne')`
|
|
4337
4365
|
* and `post('updateOne')` instead.
|
|
4338
4366
|
*
|
|
4339
|
-
* ####Example:
|
|
4367
|
+
* #### Example:
|
|
4340
4368
|
* const res = await Person.updateOne({ name: 'Jean-Luc Picard' }, { ship: 'USS Enterprise' });
|
|
4341
4369
|
* res.n; // Number of documents matched
|
|
4342
4370
|
* res.nModified; // Number of documents modified
|
|
@@ -4399,7 +4427,7 @@ Query.prototype.updateOne = function(conditions, doc, options, callback) {
|
|
|
4399
4427
|
* **Note** replaceOne will _not_ fire update middleware. Use `pre('replaceOne')`
|
|
4400
4428
|
* and `post('replaceOne')` instead.
|
|
4401
4429
|
*
|
|
4402
|
-
* ####Example:
|
|
4430
|
+
* #### Example:
|
|
4403
4431
|
* const res = await Person.replaceOne({ _id: 24601 }, { name: 'Jean Valjean' });
|
|
4404
4432
|
* res.n; // Number of documents matched
|
|
4405
4433
|
* res.nModified; // Number of documents modified
|
|
@@ -4503,7 +4531,7 @@ function _update(query, op, filter, doc, options, callback) {
|
|
|
4503
4531
|
*
|
|
4504
4532
|
* Any functions you pass to `transform()` will run **after** any post hooks.
|
|
4505
4533
|
*
|
|
4506
|
-
* ####Example:
|
|
4534
|
+
* #### Example:
|
|
4507
4535
|
*
|
|
4508
4536
|
* const res = await MyModel.findOne().transform(res => {
|
|
4509
4537
|
* // Sets a `loadedAt` property on the doc that tells you the time the
|
|
@@ -4530,7 +4558,7 @@ Query.prototype.transform = function(fn) {
|
|
|
4530
4558
|
* This is handy for integrating with async/await, because `orFail()` saves you
|
|
4531
4559
|
* an extra `if` statement to check if no document was found.
|
|
4532
4560
|
*
|
|
4533
|
-
* ####Example:
|
|
4561
|
+
* #### Example:
|
|
4534
4562
|
*
|
|
4535
4563
|
* // Throws if no doc returned
|
|
4536
4564
|
* await Model.findOne({ foo: 'bar' }).orFail();
|
|
@@ -4620,7 +4648,7 @@ function _orFailError(err, query) {
|
|
|
4620
4648
|
/**
|
|
4621
4649
|
* Executes the query
|
|
4622
4650
|
*
|
|
4623
|
-
* ####Examples:
|
|
4651
|
+
* #### Examples:
|
|
4624
4652
|
*
|
|
4625
4653
|
* const promise = query.exec();
|
|
4626
4654
|
* const promise = query.exec('update');
|
|
@@ -4760,7 +4788,7 @@ Query.prototype.catch = function(reject) {
|
|
|
4760
4788
|
* Add pre [middleware](/docs/middleware.html) to this query instance. Doesn't affect
|
|
4761
4789
|
* other queries.
|
|
4762
4790
|
*
|
|
4763
|
-
* ####Example:
|
|
4791
|
+
* #### Example:
|
|
4764
4792
|
*
|
|
4765
4793
|
* const q1 = Question.find({ answer: 42 });
|
|
4766
4794
|
* q1.pre(function middleware() {
|
|
@@ -4786,7 +4814,7 @@ Query.prototype.pre = function(fn) {
|
|
|
4786
4814
|
* Add post [middleware](/docs/middleware.html) to this query instance. Doesn't affect
|
|
4787
4815
|
* other queries.
|
|
4788
4816
|
*
|
|
4789
|
-
* ####Example:
|
|
4817
|
+
* #### Example:
|
|
4790
4818
|
*
|
|
4791
4819
|
* const q1 = Question.find({ answer: 42 });
|
|
4792
4820
|
* q1.post(function middleware() {
|
|
@@ -4885,7 +4913,7 @@ function castDoc(query, overwrite) {
|
|
|
4885
4913
|
/**
|
|
4886
4914
|
* Specifies paths which should be populated with other documents.
|
|
4887
4915
|
*
|
|
4888
|
-
* ####Example:
|
|
4916
|
+
* #### Example:
|
|
4889
4917
|
*
|
|
4890
4918
|
* let book = await Book.findOne().populate('authors');
|
|
4891
4919
|
* book.title; // 'Node.js in Action'
|
|
@@ -4992,14 +5020,14 @@ Query.prototype.populate = function() {
|
|
|
4992
5020
|
/**
|
|
4993
5021
|
* Gets a list of paths to be populated by this query
|
|
4994
5022
|
*
|
|
4995
|
-
* ####Example:
|
|
5023
|
+
* #### Example:
|
|
4996
5024
|
* bookSchema.pre('findOne', function() {
|
|
4997
5025
|
* let keys = this.getPopulatedPaths(); // ['author']
|
|
4998
5026
|
* });
|
|
4999
5027
|
* ...
|
|
5000
5028
|
* Book.findOne({}).populate('author');
|
|
5001
5029
|
*
|
|
5002
|
-
* ####Example:
|
|
5030
|
+
* #### Example:
|
|
5003
5031
|
* // Deep populate
|
|
5004
5032
|
* const q = L1.find().populate({
|
|
5005
5033
|
* path: 'level2',
|
|
@@ -5041,7 +5069,7 @@ function _getPopulatedPaths(list, arr, prefix) {
|
|
|
5041
5069
|
/**
|
|
5042
5070
|
* Casts this query to the schema of `model`
|
|
5043
5071
|
*
|
|
5044
|
-
* ####Note
|
|
5072
|
+
* #### Note
|
|
5045
5073
|
*
|
|
5046
5074
|
* If `obj` is present, it is cast instead of this query.
|
|
5047
5075
|
*
|
|
@@ -5166,7 +5194,7 @@ Query.prototype._applyPaths = function applyPaths() {
|
|
|
5166
5194
|
*
|
|
5167
5195
|
* The `.cursor()` function triggers pre find hooks, but **not** post find hooks.
|
|
5168
5196
|
*
|
|
5169
|
-
* ####Example
|
|
5197
|
+
* #### Example
|
|
5170
5198
|
*
|
|
5171
5199
|
* // There are 2 ways to use a cursor. First, as a stream:
|
|
5172
5200
|
* Thing.
|
|
@@ -5190,7 +5218,7 @@ Query.prototype._applyPaths = function applyPaths() {
|
|
|
5190
5218
|
* console.log(doc);
|
|
5191
5219
|
* }
|
|
5192
5220
|
*
|
|
5193
|
-
* ####Valid options
|
|
5221
|
+
* #### Valid options
|
|
5194
5222
|
*
|
|
5195
5223
|
* - `transform`: optional function which accepts a mongoose document. The return value of the function will be emitted on `data` and returned by `.next()`.
|
|
5196
5224
|
*
|
|
@@ -5237,7 +5265,7 @@ Query.prototype.maxscan = Query.base.maxScan;
|
|
|
5237
5265
|
/**
|
|
5238
5266
|
* Sets the tailable option (for use with capped collections).
|
|
5239
5267
|
*
|
|
5240
|
-
* ####Example
|
|
5268
|
+
* #### Example
|
|
5241
5269
|
*
|
|
5242
5270
|
* query.tailable(); // true
|
|
5243
5271
|
* query.tailable(true);
|
|
@@ -5246,7 +5274,7 @@ Query.prototype.maxscan = Query.base.maxScan;
|
|
|
5246
5274
|
* // Set both `tailable` and `awaitData` options
|
|
5247
5275
|
* query.tailable({ awaitData: true });
|
|
5248
5276
|
*
|
|
5249
|
-
* ####Note
|
|
5277
|
+
* #### Note
|
|
5250
5278
|
*
|
|
5251
5279
|
* Cannot be used with `distinct()`
|
|
5252
5280
|
*
|
|
@@ -5287,23 +5315,23 @@ Query.prototype.tailable = function(val, opts) {
|
|
|
5287
5315
|
/**
|
|
5288
5316
|
* Declares an intersects query for `geometry()`.
|
|
5289
5317
|
*
|
|
5290
|
-
* ####Example
|
|
5318
|
+
* #### Example
|
|
5291
5319
|
*
|
|
5292
5320
|
* query.where('path').intersects().geometry({
|
|
5293
|
-
*
|
|
5294
|
-
*
|
|
5295
|
-
* })
|
|
5321
|
+
* type: 'LineString',
|
|
5322
|
+
* coordinates: [[180.0, 11.0], [180, 9.0]]
|
|
5323
|
+
* });
|
|
5296
5324
|
*
|
|
5297
5325
|
* query.where('path').intersects({
|
|
5298
|
-
*
|
|
5299
|
-
*
|
|
5300
|
-
* })
|
|
5326
|
+
* type: 'LineString',
|
|
5327
|
+
* coordinates: [[180.0, 11.0], [180, 9.0]]
|
|
5328
|
+
* });
|
|
5301
5329
|
*
|
|
5302
|
-
* ####
|
|
5330
|
+
* #### Note:
|
|
5303
5331
|
*
|
|
5304
5332
|
* **MUST** be used after `where()`.
|
|
5305
5333
|
*
|
|
5306
|
-
* ####
|
|
5334
|
+
* #### Note:
|
|
5307
5335
|
*
|
|
5308
5336
|
* In Mongoose 3.7, `intersects` changed from a getter to a function. If you need the old syntax, use [this](https://github.com/ebensing/mongoose-within).
|
|
5309
5337
|
*
|
|
@@ -5320,7 +5348,7 @@ Query.prototype.tailable = function(val, opts) {
|
|
|
5320
5348
|
/**
|
|
5321
5349
|
* Specifies a `$geometry` condition
|
|
5322
5350
|
*
|
|
5323
|
-
* ####Example
|
|
5351
|
+
* #### Example
|
|
5324
5352
|
*
|
|
5325
5353
|
* const polyA = [[[ 10, 20 ], [ 10, 40 ], [ 30, 40 ], [ 30, 20 ]]]
|
|
5326
5354
|
* query.where('loc').within().geometry({ type: 'Polygon', coordinates: polyA })
|
|
@@ -5338,7 +5366,7 @@ Query.prototype.tailable = function(val, opts) {
|
|
|
5338
5366
|
*
|
|
5339
5367
|
* The argument is assigned to the most recent path passed to `where()`.
|
|
5340
5368
|
*
|
|
5341
|
-
* ####
|
|
5369
|
+
* #### Note:
|
|
5342
5370
|
*
|
|
5343
5371
|
* `geometry()` **must** come after either `intersects()` or `within()`.
|
|
5344
5372
|
*
|
|
@@ -5362,7 +5390,7 @@ Query.prototype.tailable = function(val, opts) {
|
|
|
5362
5390
|
*
|
|
5363
5391
|
* These operators return documents sorted by distance.
|
|
5364
5392
|
*
|
|
5365
|
-
* ####Example
|
|
5393
|
+
* #### Example
|
|
5366
5394
|
*
|
|
5367
5395
|
* query.where('loc').near({ center: [10, 10] });
|
|
5368
5396
|
* query.where('loc').near({ center: [10, 10], maxDistance: 5 });
|
|
@@ -5445,13 +5473,13 @@ Query.prototype.near = function() {
|
|
|
5445
5473
|
/**
|
|
5446
5474
|
* _DEPRECATED_ Specifies a `$nearSphere` condition
|
|
5447
5475
|
*
|
|
5448
|
-
* ####Example
|
|
5476
|
+
* #### Example
|
|
5449
5477
|
*
|
|
5450
5478
|
* query.where('loc').nearSphere({ center: [10, 10], maxDistance: 5 });
|
|
5451
5479
|
*
|
|
5452
5480
|
* **Deprecated.** Use `query.near()` instead with the `spherical` option set to `true`.
|
|
5453
5481
|
*
|
|
5454
|
-
* ####Example
|
|
5482
|
+
* #### Example
|
|
5455
5483
|
*
|
|
5456
5484
|
* query.where('loc').near({ center: [10, 10], spherical: true });
|
|
5457
5485
|
*
|
|
@@ -5474,7 +5502,7 @@ Query.prototype.nearSphere = function() {
|
|
|
5474
5502
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
5475
5503
|
* will call it for you.
|
|
5476
5504
|
*
|
|
5477
|
-
* ####Example
|
|
5505
|
+
* #### Example
|
|
5478
5506
|
*
|
|
5479
5507
|
* for await (const doc of Model.aggregate([{ $sort: { name: 1 } }])) {
|
|
5480
5508
|
* console.log(doc.name);
|
|
@@ -5502,10 +5530,10 @@ if (Symbol.asyncIterator != null) {
|
|
|
5502
5530
|
/**
|
|
5503
5531
|
* Specifies a `$polygon` condition
|
|
5504
5532
|
*
|
|
5505
|
-
* ####Example
|
|
5533
|
+
* #### Example
|
|
5506
5534
|
*
|
|
5507
|
-
* query.where('loc').within().polygon([10,20], [13, 25], [7,15])
|
|
5508
|
-
* query.polygon('loc', [10,20], [13, 25], [7,15])
|
|
5535
|
+
* query.where('loc').within().polygon([10, 20], [13, 25], [7, 15]);
|
|
5536
|
+
* query.polygon('loc', [10, 20], [13, 25], [7, 15]);
|
|
5509
5537
|
*
|
|
5510
5538
|
* @method polygon
|
|
5511
5539
|
* @memberOf Query
|
|
@@ -5521,7 +5549,7 @@ if (Symbol.asyncIterator != null) {
|
|
|
5521
5549
|
/**
|
|
5522
5550
|
* Specifies a `$box` condition
|
|
5523
5551
|
*
|
|
5524
|
-
* ####Example
|
|
5552
|
+
* #### Example
|
|
5525
5553
|
*
|
|
5526
5554
|
* const lowerLeft = [40.73083, -73.99756]
|
|
5527
5555
|
* const upperRight= [40.741404, -73.988135]
|
|
@@ -5558,7 +5586,7 @@ Query.prototype.box = function(ll, ur) {
|
|
|
5558
5586
|
/**
|
|
5559
5587
|
* Specifies a `$center` or `$centerSphere` condition.
|
|
5560
5588
|
*
|
|
5561
|
-
* ####Example
|
|
5589
|
+
* #### Example
|
|
5562
5590
|
*
|
|
5563
5591
|
* const area = { center: [50, 50], radius: 10, unique: true }
|
|
5564
5592
|
* query.where('loc').within().circle(area)
|
|
@@ -5603,7 +5631,7 @@ Query.prototype.center = Query.base.circle;
|
|
|
5603
5631
|
*
|
|
5604
5632
|
* **Deprecated.** Use [circle](#query_Query-circle) instead.
|
|
5605
5633
|
*
|
|
5606
|
-
* ####Example
|
|
5634
|
+
* #### Example
|
|
5607
5635
|
*
|
|
5608
5636
|
* const area = { center: [50, 50], radius: 10 };
|
|
5609
5637
|
* query.where('loc').within().centerSphere(area);
|
|
@@ -5642,9 +5670,9 @@ Query.prototype.centerSphere = function() {
|
|
|
5642
5670
|
/**
|
|
5643
5671
|
* Determines if inclusive field selection has been made.
|
|
5644
5672
|
*
|
|
5645
|
-
* query.selectedInclusively() // false
|
|
5646
|
-
* query.select('name')
|
|
5647
|
-
* query.selectedInclusively() // true
|
|
5673
|
+
* query.selectedInclusively(); // false
|
|
5674
|
+
* query.select('name');
|
|
5675
|
+
* query.selectedInclusively(); // true
|
|
5648
5676
|
*
|
|
5649
5677
|
* @method selectedInclusively
|
|
5650
5678
|
* @memberOf Query
|
|
@@ -5660,10 +5688,10 @@ Query.prototype.selectedInclusively = function selectedInclusively() {
|
|
|
5660
5688
|
/**
|
|
5661
5689
|
* Determines if exclusive field selection has been made.
|
|
5662
5690
|
*
|
|
5663
|
-
* query.selectedExclusively() // false
|
|
5664
|
-
* query.select('-name')
|
|
5665
|
-
* query.selectedExclusively() // true
|
|
5666
|
-
* query.selectedInclusively() // false
|
|
5691
|
+
* query.selectedExclusively(); // false
|
|
5692
|
+
* query.select('-name');
|
|
5693
|
+
* query.selectedExclusively(); // true
|
|
5694
|
+
* query.selectedInclusively(); // false
|
|
5667
5695
|
*
|
|
5668
5696
|
* @method selectedExclusively
|
|
5669
5697
|
* @memberOf Query
|
|
@@ -5696,4 +5724,4 @@ Query.prototype.model;
|
|
|
5696
5724
|
* Export
|
|
5697
5725
|
*/
|
|
5698
5726
|
|
|
5699
|
-
module.exports = Query;
|
|
5727
|
+
module.exports = Query;
|