|
1 |
| -The following operation appends the :method:`~cursor.showRecordId()` |
2 |
| -method to the :method:`db.collection.find()` method in order to include |
3 |
| -storage engine record information in the matching documents: |
| 1 | +The example uses this ``pizzas`` collection: |
4 | 2 |
|
5 | 3 | .. code-block:: javascript
|
6 | 4 |
|
7 |
| - db.collection.find( { a: 1 } ).showRecordId() |
| 5 | + db.pizzas.insertMany( [ |
| 6 | + { type: "pepperoni", size: "small", price: 4 }, |
| 7 | + { type: "cheese", size: "medium", price: 7 }, |
| 8 | + { type: "vegan", size: "large", price: 8 } |
| 9 | + ] ) |
8 | 10 |
|
9 |
| -The operation returns the following documents, which include the ``$recordId`` |
10 |
| -field: |
| 11 | +The following :method:`~db.collection.find()` example uses |
| 12 | +:method:`~cursor.showRecordId()` to append the ``$recordId`` to the |
| 13 | +``pizza`` document fields in the output: |
11 | 14 |
|
12 | 15 | .. code-block:: javascript
|
13 | 16 |
|
14 |
| - { |
15 |
| - "_id" : ObjectId("53908ccb18facd50a75bfbac"), |
16 |
| - "a" : 1, |
17 |
| - "b" : 1, |
18 |
| - "$recordId" : NumberLong(168112) |
19 |
| - } |
20 |
| - { |
21 |
| - "_id" : ObjectId("53908cd518facd50a75bfbad"), |
22 |
| - "a" : 1, |
23 |
| - "b" : 2, |
24 |
| - "$recordId" : NumberLong(168176) |
25 |
| - } |
26 |
| -
|
27 |
| -You can :term:`project <projection>` the added field ``$recordId``, as in the |
28 |
| -following example: |
| 17 | + db.pizzas.find().showRecordId() |
29 | 18 |
|
30 |
| -.. code-block:: javascript |
31 |
| -
|
32 |
| - db.collection.find( { a: 1 }, { $recordId: 1 } ).showRecordId() |
33 |
| -
|
34 |
| -This query returns only the ``_id`` field and the ``$recordId`` |
35 |
| -field in the matching documents: |
| 19 | +Example output: |
36 | 20 |
|
37 | 21 | .. code-block:: javascript
|
38 |
| -
|
39 |
| - { |
40 |
| - "_id" : ObjectId("53908ccb18facd50a75bfbac"), |
41 |
| - "$recordId" : NumberLong(168112) |
42 |
| - } |
43 |
| - { |
44 |
| - "_id" : ObjectId("53908cd518facd50a75bfbad"), |
45 |
| - "$recordId" : NumberLong(168176) |
46 |
| - } |
| 22 | + :copyable: false |
| 23 | +
|
| 24 | + [ |
| 25 | + { |
| 26 | + _id: ObjectId("62ffc70660b33b68e8f30435"), |
| 27 | + type: 'pepperoni', |
| 28 | + size: 'small', |
| 29 | + price: 4, |
| 30 | + '$recordId': Long("1") |
| 31 | + }, |
| 32 | + { |
| 33 | + _id: ObjectId("62ffc70660b33b68e8f30436"), |
| 34 | + type: 'cheese', |
| 35 | + size: 'medium', |
| 36 | + price: 7, |
| 37 | + '$recordId': Long("2") |
| 38 | + }, |
| 39 | + { |
| 40 | + _id: ObjectId("62ffc70660b33b68e8f30437"), |
| 41 | + type: 'vegan', |
| 42 | + size: 'large', |
| 43 | + price: 8, |
| 44 | + '$recordId': Long("3") |
| 45 | + } |
| 46 | + ] |
0 commit comments