-
Notifications
You must be signed in to change notification settings - Fork 1.7k
DOCS-151 - adding box and circle to operators list #192
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e375d1b
adding in geoOperators (box, center, near-center sphere, polygon) to …
f1d86c2
adding in cross references from within function and updating operator…
1eb44aa
added includeLocs to geoNear, rewrote uniqueDocs options
0cabed6
cleared geoNear examples from uniqueDocs
e163890
fixing up spacing in examples
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
==== | ||
$box | ||
==== | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. operator:: $box | ||
|
||
.. versionadded:: 1.4 | ||
|
||
The :operator:`$box` operator specifies a rectangular shape for the | ||
:operator:`$within` operator in :term:`geospatial` queries. To use | ||
the :operator:`$box` operator, you must specify the bottom left and | ||
top right corners of the rectangle in an array object. Consider the | ||
following example: | ||
|
||
.. code-block:: javascript | ||
|
||
db.collection.find( { loc: { $within: { $box: [ [0,0], [100,100] ] } } } ) | ||
|
||
This will return all the documents that are within the box having | ||
points at: ``[0,0]``, ``[0,100]``, ``[100,0]``, and ``[100,100]``. | ||
|
||
.. include:: /includes/note-geospatial-index-must-exist.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
======= | ||
$center | ||
======= | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. operator:: $center | ||
|
||
.. versionadded:: 1.4 | ||
|
||
This specifies a circle shape for the :operator:`$within` operator | ||
in :term:`geospatial` queries. To define the bounds of a query | ||
using :operator:`$center`, you must specify: | ||
|
||
- the center point, and | ||
|
||
- the radius | ||
|
||
Considering the following example: | ||
|
||
.. code-block:: javascript | ||
|
||
db.collection.find( { location: { $within: { $center: [ [0,0], 10 } } } ); | ||
|
||
The above command returns all the documents that fall within a | ||
10 unit radius of the point ``[0,0]``. | ||
|
||
.. include:: /includes/note-geospatial-index-must-exist.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
============= | ||
$centerSphere | ||
============= | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. operator:: $centerSphere | ||
|
||
.. versionadded:: 1.8 | ||
|
||
The :operator:`$centerSphere` operator is the spherical equivalent | ||
of the :operator:`$center` operator. :operator:`$centerSphere` uses | ||
spherical geometry to calculate distances in a circle specified by | ||
a point and radius. | ||
|
||
Considering the following example: | ||
|
||
.. code-block:: javascript | ||
|
||
db.collection.find( { loc: { $centerSphere: { [0,0], 10 / 3959 } } } ) | ||
|
||
This query will return all documents within a 10 mile radius of | ||
``[0,0]`` using a spherical geometry to calculate distances. | ||
|
||
.. include:: /includes/note-geospatial-index-must-exist.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
=========== | ||
$nearSphere | ||
=========== | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. operator:: $nearSphere | ||
|
||
.. versionadded:: 1.8 | ||
|
||
The :operator:`$nearSphere` operator is the spherical equivalent of | ||
the :operator:`$near` operator. :operator:`$nearSphere` returns all | ||
documents near a point, calculating distances using spherical geometry. | ||
|
||
.. code-block:: javascript | ||
|
||
db.collection.find( { loc: { $nearSphere: [0,0] } } ) | ||
|
||
.. include:: /includes/note-geospatial-index-must-exist.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
======== | ||
$polygon | ||
======== | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. operator:: $polygon | ||
|
||
.. versionadded:: 1.9 | ||
|
||
Use :operator:`$polygon` to specify a polgon for a bounded query | ||
using the :operator:`$within` operator for :term:`geospatial` | ||
queries. To define the polygon, you must specify an array of | ||
coordinate points, as in the following: | ||
|
||
[ [ x1,y1 ], [x2,y2], [x3,y3] ] | ||
|
||
The last point specified is always implicitly connected to the | ||
first. You can specify as many points, and therfore sides, as you | ||
like. Consider the following bounded query for documents with | ||
coordinates within a polygon: | ||
|
||
.. code-block:: javascript | ||
|
||
db.collection.find( { loc: { $within: { $polygon: [ [0,0], [3,6], [6,0] ] } } } ) | ||
|
||
.. include:: /includes/note-geospatial-index-must-exist.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,113 @@ $uniqueDocs | |
|
||
.. operator:: $uniqueDocs | ||
|
||
When using the :dbcommand:`geoNear`, if document contains more than | ||
one field with coordinate values, MongoDB will return the same | ||
document multiple times. When using the :operator:`$within`, | ||
however, MongoDB provides opposite behavior: if a document contains | ||
more than one field with coordinate values, MongoDB will only | ||
return the document once. | ||
|
||
The :operator:`$uniqueDocs` operator overrides these default | ||
behaviors. | ||
|
||
By specifying ``$uniqueDocs: false`` in a :operator:`$within` | ||
query, will cause the query to return a single document multiple | ||
times if there is more than one match. | ||
|
||
By contrast, if you specify ``uniqueDocs: true`` as an option to | ||
the a :dbcommand:`geoNear` command, then :dbcommand:`geoNear` only | ||
returns a single document even if there are multiple matches. | ||
.. versionadded:: 2.0 | ||
|
||
For :term:`geospatial` queries, MongoDB may reuturn a single | ||
document more than once for a single query, because geospatial | ||
indexes may include multiple coordinate pairs in a single | ||
document, and therefore return the same document more than once. | ||
|
||
The :operator:`$uniqueDocs` operator inverts the default behavior | ||
of these queres. By default, :dbcommand:`geoNear` will always | ||
return multiple instances of the same document, while the | ||
:operator:`$within` operator will *never* return the same document | ||
more than once. Consider the following: | ||
|
||
- For :dbcommand:`geoNear` queries, the default | ||
:operator:`$uniqueDocs` setting is ``false``. If you specify a | ||
value of ``true`` for :operator:`uniqueDocs`, MongoDB will | ||
return multiple instances of a single document. | ||
|
||
- For :operator:`$within` queries, the default | ||
:operator:`$uniqueDocs` setting is ``true``. If you specify a | ||
value of ``false`` for :operator:`uniqueDocs`, MongoDB will | ||
return multiple instances of a single document. | ||
|
||
.. example:: | ||
|
||
Given a document in the following form: | ||
|
||
.. code-block:: javascript | ||
|
||
{ addresses: [ { name: "Home", loc:[55.5,42.3]}, {name:"Work",loc:[32.3,44.2]}]} | ||
|
||
The following queries would return the same document multiple | ||
times: | ||
|
||
.. code-block:: javascript | ||
|
||
> db.runCommand( { geoNear: "geo", near: [55,44], uniqueDocs: false }) | ||
|
||
> db.geoExample.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:false } }}).pretty() | ||
|
||
The following queries would return each matching document, only | ||
once: | ||
|
||
.. code-block:: javascript | ||
|
||
> db.runCommand( { geoNear: "geo", near: [55,44], uniqueDocs: true }) | ||
|
||
> db.geo.find( {"address.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:true } }}).pretty() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commands like this don't need leading > make your collection names consistent and meaningful. records |
||
|
||
.. | ||
The following example commands in the :program:`mongo` shell | ||
illustrate this feature: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this comment please |
||
|
||
.. code-block:: javascript | ||
|
||
> db.geoExample.insert( ) | ||
> db.geoExample.ensureIndex({"addresses.loc":"2d"}) | ||
|
||
/* this will return the entry once - default for $within */ | ||
> db.geoExample.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ] } }}) | ||
/* this will return the entry twice */ | ||
> db.geoExample.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:false } }}).pretty() | ||
|
||
|
||
.. Above code output: | ||
|
||
.. code-block:: javascript | ||
|
||
> db.geoExample.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:false } }}).pretty() | ||
{ | ||
"_id" : ObjectId("504900870826ac3f09e25db6"), | ||
"addresses" : [ | ||
{ | ||
"name" : "Home", | ||
"loc" : [ | ||
55.5, | ||
42.3 | ||
] | ||
}, | ||
{ | ||
"name" : "Work", | ||
"loc" : [ | ||
32.3, | ||
44.2 | ||
] | ||
} | ||
] | ||
} | ||
{ | ||
"_id" : ObjectId("504900870826ac3f09e25db6"), | ||
"addresses" : [ | ||
{ | ||
"name" : "Home", | ||
"loc" : [ | ||
55.5, | ||
42.3 | ||
] | ||
}, | ||
{ | ||
"name" : "Work", | ||
"loc" : [ | ||
32.3, | ||
44.2 | ||
] | ||
} | ||
] | ||
} | ||
|
||
You cannot specify :operator:`$uniqueDocs` with :operator:`$near` | ||
or haystack queries. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for not seeing this sooner, but in this case, it's the uniqueDocs arument to the geonear command so most of the above is irrelevant. we don't need to document the behavior of geoNear here.