Skip to content

Commit 43eead6

Browse files
author
Andrew Leung
committed
moving and updating MinKey details.
1 parent 4b2d4aa commit 43eead6

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

source/faq/developers.txt

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -342,30 +342,8 @@ Consider the following :program:`mongo` example:
342342

343343
Mixing types for the same field is not encouraged.
344344

345-
MinKey and MaxKey
346-
~~~~~~~~~~~~~~~~~
347-
348-
MongoDB provides two special types, ``MinKey`` and ``MaxKey``, that
349-
compare less than and greater than all other possible :term:`BSON` element values,
350-
respectively.
351-
352-
To continue the example from above:
353-
354-
.. code-block:: javascript
355-
356-
db.test.insert( { x : MaxKey } )
357-
db.test.insert( { x : MinKey } )
358-
db.test.find().sort({x:1})
359-
{ "_id" : ObjectId("4b04094b7c65b846e2090112"), "x" : { $minKey : 1 } }
360-
{ "_id" : ObjectId("4b03155dce8de6586fb002c7"), "x" : 2.9 }
361-
{ "_id" : ObjectId("4b03154cce8de6586fb002c6"), "x" : 3 }
362-
{ "_id" : ObjectId("4b031566ce8de6586fb002c9"), "x" : true }
363-
{ "_id" : ObjectId("4b031563ce8de6586fb002c8"), "x" : "Tue Nov 17 2009 16:28:03 GMT-0500 (EST)" }
364-
{ "_id" : ObjectId("4b0409487c65b846e2090111"), "x" : { $maxKey : 1 } }
365-
366-
.. note::
367-
368-
These types are mostly for internal use.
345+
For more information on :term:`BSON` types, see the :ref:`$type
346+
reference <query-selectors-element>`
369347

370348
.. seealso::
371349

source/reference/operators.txt

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,38 @@ Element
477477
Max key 127
478478
======================= ==========
479479

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+
480512
.. note::
481513

482514
Query statements cannot use :operator:`$type` to test arrays
@@ -490,14 +522,9 @@ Element
490522
See the :issue:`SERVER-1475` for more information about the
491523
array type.
492524

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::
499526

500-
db.chunks.find( { "min.shardKey": { $type: -1 } } )
527+
Mixing types for the same field is not encouraged.
501528

502529
.. operator:: $regex
503530

0 commit comments

Comments
 (0)