Skip to content

Commit 91102cf

Browse files
p-mongop
andauthored
RUBY-2685 Document $query syntax for find (#2274)
Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 497238f commit 91102cf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

source/reference/crud-operations.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ notation.
173173
end
174174

175175

176+
Legacy ``$query`` Syntax
177+
------------------------
178+
179+
*This usage is deprecated.*
180+
181+
The ``find`` method allows providing the query and the options using the
182+
legacy ``$query`` syntax in the first parameter:
183+
184+
.. code-block:: ruby
185+
186+
collection.find(:'$query' => {name: 'Mr. Smith'})
187+
# Equivalent to:
188+
collection.find(name: 'Mr. Smith')
189+
190+
collection.find(:'$query' => {name: 'Mr. Smith'}, :'$sort' => {age: 1})
191+
# Equivalent to:
192+
collection.find(name: 'Mr. Smith').sort(age: 1)
193+
194+
When the query is executed against MongoDB 3.2 or newer, the driver will
195+
use the protocol appropriate for the server version in question, automatically
196+
converting the query as needed to either a find command or an OP_MSG payload.
197+
198+
176199
.. _query-options:
177200

178201
Query Options

0 commit comments

Comments
 (0)