From 4b2d4aa0bb88377270cb9026365222a8f8c29b22 Mon Sep 17 00:00:00 2001 From: Andrew Leung Date: Wed, 25 Jul 2012 08:51:49 -0400 Subject: [PATCH 1/2] adding in: for internal usage minkey is -1. --- source/reference/operators.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/reference/operators.txt b/source/reference/operators.txt index 679a112b41a..f6e998134df 100644 --- a/source/reference/operators.txt +++ b/source/reference/operators.txt @@ -480,8 +480,8 @@ Element .. 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 @@ -490,6 +490,15 @@ Element See the :issue:`SERVER-1475` for more information about the array type. + For internal usage, such as querying for the minimum value of a + shard key, the ``$minkey`` value is ``-1``. One would use the + following code to find the minimum :term:`shard key` of a + :term:`shard cluster`. + + .. code-block:: javascript + + db.chunks.find( { "min.shardKey": { $type: -1 } } ) + .. operator:: $regex The :operator:`$regex` operator provides regular expression From 43eead6114ecd700c8c9614e71e06037dd99c791 Mon Sep 17 00:00:00 2001 From: Andrew Leung Date: Wed, 25 Jul 2012 19:12:58 -0400 Subject: [PATCH 2/2] moving and updating MinKey details. --- source/faq/developers.txt | 26 ++------------------- source/reference/operators.txt | 41 ++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/source/faq/developers.txt b/source/faq/developers.txt index 64196ea0e6d..dcad7f76a2b 100644 --- a/source/faq/developers.txt +++ b/source/faq/developers.txt @@ -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 ` .. seealso:: diff --git a/source/reference/operators.txt b/source/reference/operators.txt index f6e998134df..4db6dc4056a 100644 --- a/source/reference/operators.txt +++ b/source/reference/operators.txt @@ -477,6 +477,38 @@ 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 @@ -490,14 +522,9 @@ Element See the :issue:`SERVER-1475` for more information about the array type. - For internal usage, such as querying for the minimum value of a - shard key, the ``$minkey`` value is ``-1``. One would use the - following code to find the minimum :term:`shard key` of a - :term:`shard cluster`. - - .. code-block:: javascript + .. warning:: - db.chunks.find( { "min.shardKey": { $type: -1 } } ) + Mixing types for the same field is not encouraged. .. operator:: $regex