File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 38
38
# start-batch
39
39
Band . batch_size ( 500 )
40
40
# end-batch
41
+
42
+ # start-raw
43
+ Band . where ( country : 'Argentina' ) . raw
44
+ # end-raw
45
+
46
+ # start-raw-typed
47
+ Band . where ( country : 'Argentina' ) . raw ( typed : true )
48
+ # end-raw-typed
49
+
50
+ # start-raw-false
51
+ # Retrieves raw results
52
+ results = Band . where ( members : 4 ) . raw
53
+
54
+ # ... Perform actions on results
55
+
56
+ # Returns instantiated model objects from raw results
57
+ bands = results . raw ( false ) . to_a
58
+ # end-raw-false
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ following actions to modify the way that results appear:
30
30
31
31
- :ref:`mongoid-data-skip-limit`
32
32
33
+ - :ref:`mongoid-raw-results`
34
+
33
35
Sample Data
34
36
~~~~~~~~~~~
35
37
@@ -306,6 +308,43 @@ The following code sets the batch size to ``500``:
306
308
:language: ruby
307
309
:dedent:
308
310
311
+ .. _mongoid-raw-results:
312
+
313
+ Return Raw Data
314
+ ---------------
315
+
316
+ You can return results as raw hashes without creating model instances by
317
+ chaining the ``raw`` method to your query.
318
+
319
+ The following code retrieves the query results as raw hashes:
320
+
321
+ .. literalinclude:: /includes/interact-data/modify-results.rb
322
+ :start-after: start-raw
323
+ :end-before: end-raw
324
+ :language: ruby
325
+ :dedent:
326
+
327
+ By default, the ``raw`` method returns documents exactly as {+odm+}
328
+ receives them from the database. You can optionally cast fields in your
329
+ result hashes to the types from your model field declarations by setting
330
+ the ``typed`` option to ``true`` in the ``raw`` method:
331
+
332
+ .. literalinclude:: /includes/interact-data/modify-results.rb
333
+ :start-after: start-raw-typed
334
+ :end-before: end-raw-typed
335
+ :language: ruby
336
+ :dedent:
337
+
338
+ If you perform a query that returns raw results and later want to
339
+ convert these results into models, you can call ``raw(false)`` on the
340
+ results:
341
+
342
+ .. literalinclude:: /includes/interact-data/modify-results.rb
343
+ :start-after: start-raw-false
344
+ :end-before: end-raw-false
345
+ :language: ruby
346
+ :dedent:
347
+
309
348
Additional Information
310
349
----------------------
311
350
Original file line number Diff line number Diff line change @@ -12,11 +12,24 @@ What's New
12
12
13
13
Learn what's new in:
14
14
15
+ * :ref:`Version 9.1 <mongoid-version-9.1>`
15
16
* :ref:`Version 9.0 <mongoid-version-9.0>`
16
17
17
18
To view a list of releases and detailed release notes, see {+odm+}
18
19
:github:`Releases <mongodb/mongoid/releases>` on GitHub.
19
20
21
+ .. _mongoid-version-9.1:
22
+
23
+ What's New in 9.1
24
+ -----------------
25
+
26
+ The 9.1 release includes the following new features, improvements, and
27
+ fixes:
28
+
29
+ - Adds the ``Criteria#raw`` method that allows you to retrieve results
30
+ as raw hashes. To learn more, see the :ref:`mongoid-raw-results`
31
+ section of the Modify Query Results guide.
32
+
20
33
.. _mongoid-version-9.0:
21
34
22
35
What's New in 9.0
You can’t perform that action at this time.
0 commit comments