Skip to content

Update type min key #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions source/faq/developers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,30 +342,8 @@ Consider the following :program:`mongo` example:

Mixing types for the same field is not encouraged.

MinKey and MaxKey
~~~~~~~~~~~~~~~~~

MongoDB provides two special types, ``MinKey`` and ``MaxKey``, that
compare less than and greater than all other possible :term:`BSON` element values,
respectively.

To continue the example from above:

.. code-block:: javascript

db.test.insert( { x : MaxKey } )
db.test.insert( { x : MinKey } )
db.test.find().sort({x:1})
{ "_id" : ObjectId("4b04094b7c65b846e2090112"), "x" : { $minKey : 1 } }
{ "_id" : ObjectId("4b03155dce8de6586fb002c7"), "x" : 2.9 }
{ "_id" : ObjectId("4b03154cce8de6586fb002c6"), "x" : 3 }
{ "_id" : ObjectId("4b031566ce8de6586fb002c9"), "x" : true }
{ "_id" : ObjectId("4b031563ce8de6586fb002c8"), "x" : "Tue Nov 17 2009 16:28:03 GMT-0500 (EST)" }
{ "_id" : ObjectId("4b0409487c65b846e2090111"), "x" : { $maxKey : 1 } }

.. note::

These types are mostly for internal use.
For more information on :term:`BSON` types, see the :ref:`$type
reference <query-selectors-element>`

.. seealso::

Expand Down
40 changes: 38 additions & 2 deletions source/reference/operators.txt
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,43 @@ Element
Max key 127
======================= ==========

``MinKey`` and ``MaxKey`` compare less than and greater than all
other possible :term:`BSON` element values, respectively.

For example:

.. code-block:: javascript

db.test.insert( {x : 3});
db.test.insert( {x : 2.9} );
db.test.insert( {x : new Date()} );
db.test.insert( {x : true } );
db.test.insert( {x : MaxKey } )
db.test.insert( {x : MinKey } )
db.test.find().sort({x:1})
{ "_id" : ObjectId("4b04094b7c65b846e2090112"), "x" : { $minKey : 1 } }
{ "_id" : ObjectId("4b03155dce8de6586fb002c7"), "x" : 2.9 }
{ "_id" : ObjectId("4b03154cce8de6586fb002c6"), "x" : 3 }
{ "_id" : ObjectId("4b031566ce8de6586fb002c9"), "x" : true }
{ "_id" : ObjectId("4b031563ce8de6586fb002c8"), "x" : "Tue Jul 25 2012 18:42:03 GMT-0500 (EST)" }
{ "_id" : ObjectId("4b0409487c65b846e2090111"), "x" : { $maxKey : 1 } }

.. note::

For internal usage, the ``MinKey`` value is ``-1`` due to the
way ``MinKey`` is evaluated. For operations such as querying
for the minimum value of a :term:`shard key` of a :term:`shard
cluster`, use the following code:

.. code-block:: javascript

db.chunks.find( { "min.shardKey": { $type: -1 } } )

.. note::

Query statements cannot use :operator:`$type` to test arrays
(i.e. ``4``.) Instead use an operation with the
:operator:`$where` that resembles the following:
(i.e. ``4``.) Instead, use the :operator:`$where` operator that
resembles the following:

.. code-block:: javascript

Expand All @@ -490,6 +522,10 @@ Element
See the :issue:`SERVER-1475` for more information about the
array type.

.. warning::

Mixing types for the same field is not encouraged.

.. operator:: $regex

The :operator:`$regex` operator provides regular expression
Expand Down