@@ -477,6 +477,38 @@ Element
477
477
Max key 127
478
478
======================= ==========
479
479
480
+ ``MinKey`` and ``MaxKey`` compare less than and greater than all
481
+ other possible :term:`BSON` element values, respectively.
482
+
483
+ For example:
484
+
485
+ .. code-block:: javascript
486
+
487
+ db.test.insert( {x : 3});
488
+ db.test.insert( {x : 2.9} );
489
+ db.test.insert( {x : new Date()} );
490
+ db.test.insert( {x : true } );
491
+ db.test.insert( {x : MaxKey } )
492
+ db.test.insert( {x : MinKey } )
493
+ db.test.find().sort({x:1})
494
+ { "_id" : ObjectId("4b04094b7c65b846e2090112"), "x" : { $minKey : 1 } }
495
+ { "_id" : ObjectId("4b03155dce8de6586fb002c7"), "x" : 2.9 }
496
+ { "_id" : ObjectId("4b03154cce8de6586fb002c6"), "x" : 3 }
497
+ { "_id" : ObjectId("4b031566ce8de6586fb002c9"), "x" : true }
498
+ { "_id" : ObjectId("4b031563ce8de6586fb002c8"), "x" : "Tue Jul 25 2012 18:42:03 GMT-0500 (EST)" }
499
+ { "_id" : ObjectId("4b0409487c65b846e2090111"), "x" : { $maxKey : 1 } }
500
+
501
+ .. note::
502
+
503
+ For internal usage, the ``MinKey`` value is ``-1`` due to the
504
+ way ``MinKey`` is evaluated. For operations such as querying
505
+ for the minimum value of a :term:`shard key` of a :term:`shard
506
+ cluster`, use the following code:
507
+
508
+ .. code-block:: javascript
509
+
510
+ db.chunks.find( { "min.shardKey": { $type: -1 } } )
511
+
480
512
.. note::
481
513
482
514
Query statements cannot use :operator:`$type` to test arrays
@@ -490,14 +522,9 @@ Element
490
522
See the :issue:`SERVER-1475` for more information about the
491
523
array type.
492
524
493
- For internal usage, such as querying for the minimum value of a
494
- shard key, the ``$minkey`` value is ``-1``. One would use the
495
- following code to find the minimum :term:`shard key` of a
496
- :term:`shard cluster`.
497
-
498
- .. code-block:: javascript
525
+ .. warning::
499
526
500
- db.chunks.find( { "min.shardKey": { $type: -1 } } )
527
+ Mixing types for the same field is not encouraged.
501
528
502
529
.. operator:: $regex
503
530
0 commit comments