Skip to content

Commit e26cd4c

Browse files
committed
SA review
1 parent 83a9f44 commit e26cd4c

File tree

6 files changed

+15
-23
lines changed

6 files changed

+15
-23
lines changed

source/code-snippets/usage-examples/find.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ async function run() {
1414

1515
// Query for movies that have a runtime less than 15 minutes
1616
const query = { runtime: { $lt: 15 } };
17-
const sort = { title: 1 };
18-
const projection = { _id: 0, title: 1, imdb: 1 };
17+
const sortFields = { title: 1 };
18+
const projectFields = { _id: 0, title: 1, imdb: 1 };
1919

2020
// Execute query
21-
const cursor = movies.find(query).sort(sort).project(projection);
21+
const cursor = movies.find(query).sort(sortFields).project(projectFields);
2222

2323
// Print a message if no documents were found
2424
if ((await movies.countDocuments(query)) === 0) {

source/code-snippets/usage-examples/find.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ async function run() {
2525
const movies = database.collection<Movie>("movies");
2626

2727
const query = { runtime: { $lt: 15 } };
28-
const sort = { title: 1 };
29-
const projection = { _id: 0, title: 1, imdb: 1 };
28+
const sortFields = { title: 1 };
29+
const projectFields = { _id: 0, title: 1, imdb: 1 };
3030

31-
const cursor = movies.find<Movie>(query).sort(sort).project(projection);
31+
const cursor = movies.find<Movie>(query).sort(sortFields).project(projectFields);
3232

3333
if ((await movies.countDocuments(query)) === 0) {
3434
console.warn("No documents found!");

source/crud/query/project.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,4 @@ the following results:
150150
For more projection examples, see the
151151
:manual:`MongoDB Manual page on Project Fields to Return from Query </tutorial/project-fields-from-query-results/>`.
152152

153-
.. note::
154-
155-
You must chain a cursor method such as ``project()`` to a read operation
156-
before iterating the cursor. If you specify a projection after
157-
iterating the cursor, the projection does not apply to the operation.
153+
.. include:: /includes/crud/chain-cursor-methods.rst

source/crud/query/retrieve.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,7 @@ Running the preceding example results in the following output:
235235
{ title: '8', imdb: { rating: 7.8, votes: 883, id: 1592502 } }
236236
...
237237

238-
.. note::
239-
240-
You must chain cursor methods such as ``sort()`` or ``project()``
241-
to a read operation before iterating the cursor. If you specify
242-
a cursor method after iterating the cursor, the setting does not
243-
apply to the read operation.
238+
.. include:: /includes/crud/chain-cursor-methods.rst
244239

245240
Additional Information
246241
~~~~~~~~~~~~~~~~~~~~~~

source/crud/query/specify-documents-to-return.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ that describe books into the ``myDB.books`` collection:
4747
{ "_id": 6, "name": "A Dance With Dragons", "author": "Martin", "length": 1104 },
4848
]);
4949

50-
.. note::
51-
52-
You must chain a cursor method such as ``sort()``, ``limit()``, or
53-
``skip()`` to a read operation before iterating the cursor. If you specify
54-
a cursor method after iterating the cursor, the setting does not
55-
apply to the read operation.
50+
.. include:: /includes/crud/chain-cursor-methods.rst
5651

5752
.. include:: /includes/access-cursor-note.rst
5853

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. note::
2+
3+
You must chain a cursor method such as ``sort()``, ``limit()``,
4+
``skip()``, or ``project()`` to a read operation before iterating the cursor.
5+
If you specify a cursor method after iterating the cursor, the setting does
6+
not apply to the read operation.

0 commit comments

Comments
 (0)