DOCSP-48381 make specify docs page#1037
Conversation
✅ Deploy Preview for docs-node ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
norareidy
left a comment
There was a problem hiding this comment.
Nice work! I left some copy edits that aren't really in scope for this ticket, so feel free to ignore S: comments you don't think are necessary
| - ``skip``: Specifies the number of documents to skip before returning query results. | ||
|
|
There was a problem hiding this comment.
S: can't comment on lines 26-27 but since these are method names, I'd add () to the end of each
| - ``skip``: Specifies the number of documents to skip before returning query results. | |
| - ``skip()``: Specifies the number of documents to skip before returning query results. | |
There was a problem hiding this comment.
applies to all mentions of the skip(), sort(), limit() methods
| Sample Data for Examples | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| To follow the examples in this guide, use the following code snippet to insert documents |
There was a problem hiding this comment.
S: [nit] to avoid repeating follow/following
| To follow the examples in this guide, use the following code snippet to insert documents | |
| To run the examples in this guide, use the following code snippet to insert documents |
| Limit | ||
| ----- | ||
|
|
||
| Use ``limit`` to cap the number of documents that can be returned from a read operation. |
There was a problem hiding this comment.
S:
| Use ``limit`` to cap the number of documents that can be returned from a read operation. | |
| Use the ``limit()`` method to cap the number of documents that can be returned from a read operation. |
| ----- | ||
|
|
||
| Use ``limit`` to cap the number of documents that can be returned from a read operation. | ||
| ``limit`` functions as a cap on the maximum number of |
There was a problem hiding this comment.
S: a little more concise
| ``limit`` functions as a cap on the maximum number of | |
| ``limit`` specifies the maximum number of |
| The following example queries the collection to return the top three | ||
| longest books. It matches all documents because the query filter is | ||
| empty. Then, it applies a descending ``sort`` on the ``length`` field to | ||
| return longer books before shorter books and a ``limit`` to | ||
| return only the ``3`` first results: |
There was a problem hiding this comment.
S: this might be outside the scope of this PR so optional, but I'd turn this code description into a bulleted list
| that are returned. The driver automatically reorders the calls to perform the | ||
| sort and skip operations first, and the limit operation afterward. | ||
|
|
||
| You can also limit, sort, and skip results by specifying them as |
There was a problem hiding this comment.
I: the previous example does specify these as parameters (an options parameter) to the find() method. Either you can show how to specify each as methods chained to find(), or omit this part
|
|
||
| The following example returns documents with the ``length`` value of | ||
| ``"1104"``. The results are sorted in alphabetical order, skipping the first | ||
| document: |
There was a problem hiding this comment.
I: this example is missing limit
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| To learn more about any of the methods or types discussed in this | ||
| guide, see the following API Documentation: |
There was a problem hiding this comment.
S:
| guide, see the following API Documentation: | |
| guide, see the following API documentation: |
| cursor that contains matching documents. To learn how to | ||
| examine data stored in the cursor, see the | ||
| :doc:`Cursor Fundamentals page </fundamentals/crud/read-operations/cursor>`. No newline at end of file | ||
| :doc:`Access Data From a Cursor page </crud/query/cursor>`. No newline at end of file |
There was a problem hiding this comment.
S: you can use :ref: here instead of :doc:
| API Documentation | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| To learn more about any of the methods or types discussed in this |
There was a problem hiding this comment.
S: since these are just methods
| To learn more about any of the methods or types discussed in this | |
| To learn more about any of the methods discussed in this |
norareidy
left a comment
There was a problem hiding this comment.
LGTM with final suggestions, let me know if you want me to take another look
| The following example queries the collection to return the top three | ||
| longest books. | ||
|
|
||
| - The query matches all documents because the query filter is empty. | ||
| - The descending ``sort()`` method on the ``length`` field returns longer books before shorter books. | ||
| - The ``limit()`` method specifies returning only the first ``3`` results. |
There was a problem hiding this comment.
S:
| The following example queries the collection to return the top three | |
| longest books. | |
| - The query matches all documents because the query filter is empty. | |
| - The descending ``sort()`` method on the ``length`` field returns longer books before shorter books. | |
| - The ``limit()`` method specifies returning only the first ``3`` results. | |
| This example performs the following actions: | |
| - Uses an empty query filter to match all documents in the collection | |
| - Calls the ``sort()`` method to apply a descending sort on the ``length`` field to the results | |
| - Calls the ``limit()`` method to return only the first ``3`` results |
| - The ``limit()`` method specifies returning only the first ``3`` results. | ||
|
|
||
| .. code-block:: javascript | ||
| :emphasize-lines: 4 |
There was a problem hiding this comment.
S: emphasize limit instead of sort
| :emphasize-lines: 4 | |
| :emphasize-lines: 5 |
| .. _node-fundamentals-sort: | ||
|
|
||
| Sort | ||
| ---- |
There was a problem hiding this comment.
Okay I actually think the Sort section should come first (before both skip and limit) since it's used in both of them, should've clarified that last time oops
| { "_id": 1, "title": "The Brothers Karamazov", "author": "Dostoyevsky", "length": 824 } | ||
|
|
||
| Sometimes, the order of two or more documents is ambiguous using a specified sort. In the | ||
| above case,the documents that have ``title`` values of ``"A Dance with Dragons"`` and |
There was a problem hiding this comment.
S: "preceding" + missing space
| above case,the documents that have ``title`` values of ``"A Dance with Dragons"`` and | |
| preceding example, the documents that have ``title`` values of ``"A Dance with Dragons"`` and |
| Use the ``skip()`` method to omit documents from the beginning of the list of | ||
| returned documents for a read operation. You can combine ``skip()`` with |
There was a problem hiding this comment.
S:
| Use the ``skip()`` method to omit documents from the beginning of the list of | |
| returned documents for a read operation. You can combine ``skip()`` with | |
| Use the ``skip()`` method to omit documents from the beginning of the read operation results. You can combine ``skip()`` with |
| The following example queries the collection for the books with the second and third | ||
| highest lengths. | ||
|
|
||
| - The query matches all documents because the query filter is empty. | ||
| - The descending ``sort()`` method on the ``length`` field returns longer books before shorter books. | ||
| - The ``skip()`` method specifies that the first matching document is omitted from the result. |
There was a problem hiding this comment.
S:
| The following example queries the collection for the books with the second and third | |
| highest lengths. | |
| - The query matches all documents because the query filter is empty. | |
| - The descending ``sort()`` method on the ``length`` field returns longer books before shorter books. | |
| - The ``skip()`` method specifies that the first matching document is omitted from the result. | |
| This example queries the collection for the books with the second and third | |
| highest lengths by performing the following actions: | |
| - Uses an empty query filter to match all documents in the collection | |
| - Calls the ``sort()`` method to apply a descending sort to the ``length`` field, which returns longer books before shorter books | |
| - Calls the ``skip()`` method to omit the first matching document from the result |
| document and specifies returning only the first result: | ||
|
|
||
| .. code-block:: javascript | ||
| :emphasize-lines: 5 |
There was a problem hiding this comment.
S: I don't think you need to emphasize any lines here
|
|
||
| The following example returns documents with the ``length`` value of | ||
| ``"1104"``. The results are sorted in alphabetical order, skipping the first | ||
| document and specifies returning only the first result: |
There was a problem hiding this comment.
S:
| document and specifies returning only the first result: | |
| document and including only the first result: |
| Combine Limit, Sort, and Skip | ||
| ----------------------------- | ||
|
|
||
| You can combine the ``limit()``, ``sort()``, and ``skip()`` options in a single |
There was a problem hiding this comment.
S: since you're talking about the options here, not the methods, you can remove the ()
| You can combine the ``limit()``, ``sort()``, and ``skip()`` options in a single | |
| You can combine the ``limit``, ``sort``, and ``skip`` options in a single |
| - ``limit()``: Specifies the maximum number of documents to return from a query. | ||
| - ``skip()``: Specifies the number of documents to skip before returning query results. | ||
|
|
||
| Sample Data for Examples |
There was a problem hiding this comment.
I'm not sure the best place to mention this or honestly if it is even worth mentioning - but if you use the chaining API you must specify all options before starting to iterate the cursor.
const cursor = find();
await cursor.next();
cursor.limit(5); // does not workShould we mention this limitation of the builder API somewhere?
There was a problem hiding this comment.
I think this is good information for users to have, thanks for informing me! I added a note about it in the overview section, let me know if the wording is technically correct! Do you know where the API documentation about this would be/if there is any? I was looking in https://mongodb.github.io/node-mongodb-native/6.15/ but couldn't find anything specifically about the chaining API.
There was a problem hiding this comment.
We don't document this, although it might be nice to add to our doc comments. I looked at the code though and we actually throw an error in this scenario. For example, here's the source code for limit:
/**
* Set the limit for the cursor.
*
* @param value - The limit for the cursor query.
*/
limit(value: number): this {
this.throwIfInitialized(); // <-- here we throw
if (this.findOptions.tailable) {
throw new MongoTailableCursorError('Tailable cursor does not support limit');
}
if (typeof value !== 'number') {
throw new MongoInvalidArgumentError('Operation "limit" requires an integer');
}
this.findOptions.limit = value;
return this;
}
So I guess, anybody who tries to set these values after the cursor is initialized would see errors. Given that, do you think its worth documenting explicitly here as well? We could also just add a note to the API docs that specify that they will throw if the cursor is initialized.
Also, its worth mentioning that this applies to all our cursor chaining APIs, not just skip/limit/sort. So if we document it, it would be nice to document this behavior more generally than just for these three options, I think? This error is thrown for any option that affects the actual cursor command the driver sends (ex: project, allowDiskUse, comment, etc).
There was a problem hiding this comment.
I think we can still leave this note in these docs for now, and based on our discussion in slack about standardization, we also made another ticket about adding a note about this cursor chaining behavior.
* make specify docs page * fix includes link * fix link * fix highlighting and links * remove passive * nr feedback * final edits * fix typo * nr feedback * tech review * fix wording * Fix spacing * spacing change * Update connection-targets.txt * Update access-cursor-note.rst * Update access-cursor-note.rst
* DOCSP-48375 ToC reorg part one (#1035) * DOCSP-48376: Get Started edits (#1039) * DOCSP-48376: Get Started edits * edits * RR feedback * DOCSP-48384: Atlas search (#1041) * DOCSP-48384: Atlas search * edits * tech feedback * DOCSP-48378 make mongoclient page (#1038) * make mongoclient page * fix link: * fix link * add anchor to page to avoid broken link * nr feedback * nb feedback * monospace * DOCSP-48383 document bson (#1044) * make bson page * edit code * fix spacing * capitalization * change copy * nb edits * DOCSP-48493: Databases & collections (#1045) * DOCSP-48493: Databases & collections * edits * SA feedback * typo * DOCSP-48385 Make Atlas Vector Search page (#1042) * make page * fix vale * remove extra space * add to index * fix link * fix link * fix quotes * fix quotes * lm feedback * fix spacing * remove extra code * fix spacing * fix link * fix link title * change copy * lm review * change spacing * lm edits * remove extra words * nb edits * remove extra quotes * fix quotes * add quote * change quote * nb feedback * DOCSP-48377 Authentication Reorg (#1040) * DOCSP-48377 Authentication Reorg * start building TOC * full draft * edits * edits * SA comments * SA update redirect * Edit table * DOCSP-48379 Connection Targets (#1043) * DOCSP-48379 Connection Targets * edits * edits * last edits * one more * ignoring vale check * eol for file * NR review * vale check * DOCSP-48381 make specify docs page (#1037) * make specify docs page * fix includes link * fix link * fix highlighting and links * remove passive * nr feedback * final edits * fix typo * nr feedback * tech review * fix wording * Fix spacing * spacing change * Update connection-targets.txt * Update access-cursor-note.rst * Update access-cursor-note.rst * DOCSP-48388 break up faq (#1048) * break up faq * vale errors * fix vale error * wording * add redirect * remove faq * change headlines * js feedback * bp edits * bp feedback * DOCSP-48592 Security Landing Page (#1064) * DOCSP-48592 Security Landing Page * remove sample app * change title * DOCSP-48608 Edit AVS and AS section on Indexes page (#1065) * DOCSP-48606 Atlas Vector Search * edit existing sections * Edits * edit code comments * add link to as query guide * title change * more edits * DOCSP-48382: Configure CRUD operations (#1049) * DOCSP-48382: Configure CRUD operations * edits, move info * edits * AS feedback * tech feedback * DOCSP-48386 Add monitoring page (#1046) * DOCSP-48683 Refine Connection Pools page (#1067) * DOCSP-48501 add casual consistency section (#1047) * add casual consistency section: * change find to findone * DOCSP-49031 UUID (#1072) * DOCSP-48717 UUID * DOCSP-49031 UUID * edits * edit import * edit * edit * JS review * tech review * DOCSP-48390 Document Data Formats: EJSON (#1069) * DOCSP-48390 Document Data Formats: EJSON * add to toc and bson import note * edit * add binary type * edit ouputs * remove additional info section * last small edits * fix link * edit * tech review * edits * tech review 2 * add note about bad orange highlighting * tech review * DOCSP-48487 Move usage examples (#1071) * DOCSP-48389 Connection Troubleshooting Revisions (#1068) * DOCSP-48389 Connection Troubleshooting Revisions * tech question * edits * tech review * edit * remov * technical review * security comment * JS review * edit * DOCSP-48707 Standardize cursor chaining methods (#1073) * DOCSP-48707 Standardize cursor chaining methods * tech review * edits * vale check * remove mention of options object * order comment * RR review * DOCSP-48708 Specify cursor limitations (#1094) * DOCSP-48708 Specify cursor limitations * add chaining method to find * edit * edit find ts example * SA review * change cursor chain const names to be more specific * DOCSP-48497 Comp cov clean up (#1095) * add back old refs * get started --------- Co-authored-by: Stephanie <52582720+stephmarie17@users.noreply.github.com> Co-authored-by: Nora Reidy <nora.reidy@mongodb.com> Co-authored-by: shuangela <angela.shu@mongodb.com>
* DOCSP-48375 ToC reorg part one (mongodb#1035) * DOCSP-48376: Get Started edits (mongodb#1039) * DOCSP-48376: Get Started edits * edits * RR feedback * DOCSP-48384: Atlas search (mongodb#1041) * DOCSP-48384: Atlas search * edits * tech feedback * DOCSP-48378 make mongoclient page (mongodb#1038) * make mongoclient page * fix link: * fix link * add anchor to page to avoid broken link * nr feedback * nb feedback * monospace * DOCSP-48383 document bson (mongodb#1044) * make bson page * edit code * fix spacing * capitalization * change copy * nb edits * DOCSP-48493: Databases & collections (mongodb#1045) * DOCSP-48493: Databases & collections * edits * SA feedback * typo * DOCSP-48385 Make Atlas Vector Search page (mongodb#1042) * make page * fix vale * remove extra space * add to index * fix link * fix link * fix quotes * fix quotes * lm feedback * fix spacing * remove extra code * fix spacing * fix link * fix link title * change copy * lm review * change spacing * lm edits * remove extra words * nb edits * remove extra quotes * fix quotes * add quote * change quote * nb feedback * DOCSP-48377 Authentication Reorg (mongodb#1040) * DOCSP-48377 Authentication Reorg * start building TOC * full draft * edits * edits * SA comments * SA update redirect * Edit table * DOCSP-48379 Connection Targets (mongodb#1043) * DOCSP-48379 Connection Targets * edits * edits * last edits * one more * ignoring vale check * eol for file * NR review * vale check * DOCSP-48381 make specify docs page (mongodb#1037) * make specify docs page * fix includes link * fix link * fix highlighting and links * remove passive * nr feedback * final edits * fix typo * nr feedback * tech review * fix wording * Fix spacing * spacing change * Update connection-targets.txt * Update access-cursor-note.rst * Update access-cursor-note.rst * DOCSP-48388 break up faq (mongodb#1048) * break up faq * vale errors * fix vale error * wording * add redirect * remove faq * change headlines * js feedback * bp edits * bp feedback * DOCSP-48592 Security Landing Page (mongodb#1064) * DOCSP-48592 Security Landing Page * remove sample app * change title * DOCSP-48608 Edit AVS and AS section on Indexes page (mongodb#1065) * DOCSP-48606 Atlas Vector Search * edit existing sections * Edits * edit code comments * add link to as query guide * title change * more edits * DOCSP-48382: Configure CRUD operations (mongodb#1049) * DOCSP-48382: Configure CRUD operations * edits, move info * edits * AS feedback * tech feedback * DOCSP-48386 Add monitoring page (mongodb#1046) * DOCSP-48683 Refine Connection Pools page (mongodb#1067) * DOCSP-48501 add casual consistency section (mongodb#1047) * add casual consistency section: * change find to findone * DOCSP-49031 UUID (mongodb#1072) * DOCSP-48717 UUID * DOCSP-49031 UUID * edits * edit import * edit * edit * JS review * tech review * DOCSP-48390 Document Data Formats: EJSON (mongodb#1069) * DOCSP-48390 Document Data Formats: EJSON * add to toc and bson import note * edit * add binary type * edit ouputs * remove additional info section * last small edits * fix link * edit * tech review * edits * tech review 2 * add note about bad orange highlighting * tech review * DOCSP-48487 Move usage examples (mongodb#1071) * DOCSP-48389 Connection Troubleshooting Revisions (mongodb#1068) * DOCSP-48389 Connection Troubleshooting Revisions * tech question * edits * tech review * edit * remov * technical review * security comment * JS review * edit * DOCSP-48707 Standardize cursor chaining methods (mongodb#1073) * DOCSP-48707 Standardize cursor chaining methods * tech review * edits * vale check * remove mention of options object * order comment * RR review * DOCSP-48708 Specify cursor limitations (mongodb#1094) * DOCSP-48708 Specify cursor limitations * add chaining method to find * edit * edit find ts example * SA review * change cursor chain const names to be more specific * DOCSP-48497 Comp cov clean up (mongodb#1095) * add back old refs * get started --------- Co-authored-by: Stephanie <52582720+stephmarie17@users.noreply.github.com> Co-authored-by: Nora Reidy <nora.reidy@mongodb.com> Co-authored-by: shuangela <angela.shu@mongodb.com> (cherry picked from commit 1e62fc0)
* Node CC merge comp-cov branch (#1096) * DOCSP-48375 ToC reorg part one (#1035) * DOCSP-48376: Get Started edits (#1039) * DOCSP-48376: Get Started edits * edits * RR feedback * DOCSP-48384: Atlas search (#1041) * DOCSP-48384: Atlas search * edits * tech feedback * DOCSP-48378 make mongoclient page (#1038) * make mongoclient page * fix link: * fix link * add anchor to page to avoid broken link * nr feedback * nb feedback * monospace * DOCSP-48383 document bson (#1044) * make bson page * edit code * fix spacing * capitalization * change copy * nb edits * DOCSP-48493: Databases & collections (#1045) * DOCSP-48493: Databases & collections * edits * SA feedback * typo * DOCSP-48385 Make Atlas Vector Search page (#1042) * make page * fix vale * remove extra space * add to index * fix link * fix link * fix quotes * fix quotes * lm feedback * fix spacing * remove extra code * fix spacing * fix link * fix link title * change copy * lm review * change spacing * lm edits * remove extra words * nb edits * remove extra quotes * fix quotes * add quote * change quote * nb feedback * DOCSP-48377 Authentication Reorg (#1040) * DOCSP-48377 Authentication Reorg * start building TOC * full draft * edits * edits * SA comments * SA update redirect * Edit table * DOCSP-48379 Connection Targets (#1043) * DOCSP-48379 Connection Targets * edits * edits * last edits * one more * ignoring vale check * eol for file * NR review * vale check * DOCSP-48381 make specify docs page (#1037) * make specify docs page * fix includes link * fix link * fix highlighting and links * remove passive * nr feedback * final edits * fix typo * nr feedback * tech review * fix wording * Fix spacing * spacing change * Update connection-targets.txt * Update access-cursor-note.rst * Update access-cursor-note.rst * DOCSP-48388 break up faq (#1048) * break up faq * vale errors * fix vale error * wording * add redirect * remove faq * change headlines * js feedback * bp edits * bp feedback * DOCSP-48592 Security Landing Page (#1064) * DOCSP-48592 Security Landing Page * remove sample app * change title * DOCSP-48608 Edit AVS and AS section on Indexes page (#1065) * DOCSP-48606 Atlas Vector Search * edit existing sections * Edits * edit code comments * add link to as query guide * title change * more edits * DOCSP-48382: Configure CRUD operations (#1049) * DOCSP-48382: Configure CRUD operations * edits, move info * edits * AS feedback * tech feedback * DOCSP-48386 Add monitoring page (#1046) * DOCSP-48683 Refine Connection Pools page (#1067) * DOCSP-48501 add casual consistency section (#1047) * add casual consistency section: * change find to findone * DOCSP-49031 UUID (#1072) * DOCSP-48717 UUID * DOCSP-49031 UUID * edits * edit import * edit * edit * JS review * tech review * DOCSP-48390 Document Data Formats: EJSON (#1069) * DOCSP-48390 Document Data Formats: EJSON * add to toc and bson import note * edit * add binary type * edit ouputs * remove additional info section * last small edits * fix link * edit * tech review * edits * tech review 2 * add note about bad orange highlighting * tech review * DOCSP-48487 Move usage examples (#1071) * DOCSP-48389 Connection Troubleshooting Revisions (#1068) * DOCSP-48389 Connection Troubleshooting Revisions * tech question * edits * tech review * edit * remov * technical review * security comment * JS review * edit * DOCSP-48707 Standardize cursor chaining methods (#1073) * DOCSP-48707 Standardize cursor chaining methods * tech review * edits * vale check * remove mention of options object * order comment * RR review * DOCSP-48708 Specify cursor limitations (#1094) * DOCSP-48708 Specify cursor limitations * add chaining method to find * edit * edit find ts example * SA review * change cursor chain const names to be more specific * DOCSP-48497 Comp cov clean up (#1095) * add back old refs * get started --------- Co-authored-by: Stephanie <52582720+stephmarie17@users.noreply.github.com> Co-authored-by: Nora Reidy <nora.reidy@mongodb.com> Co-authored-by: shuangela <angela.shu@mongodb.com> (cherry picked from commit 1e62fc0) * Backport v6.16 NodeCC * fix redirect --------- Co-authored-by: Stephanie <52582720+stephmarie17@users.noreply.github.com> Co-authored-by: Nora Reidy <nora.reidy@mongodb.com> Co-authored-by: shuangela <angela.shu@mongodb.com>
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-48381
Staging - https://deploy-preview-1037--docs-node.netlify.app/crud/query/specify-documents-to-return/
Self-Review Checklist