| Start |
|---|
| Find() retrieve all documents in a collection retrieve documents in a collection using a condition ( similar to WHERE in MYSQL ) retrieve documents in a collection using Boolean conditions (Query Operators) more boolean operations and examples can be found here (opens new window) NOTE: find() will keep on searching the collection even if a document match has been found , therefore it is inefficient when used in a large collection , however by carefully modeling your data and/or using indexes you can increase the efficiency of find() |
FindOne() the querying functionality is similar to find() but this will end execution the moment it finds one document matching its condition , if used with and empty object , it will fetch the first document and return it . findOne() mongodb api documentation (opens new window) |
| limit, skip, sort and count the results of the find() method Similar to aggregation methods also by the find() method you have the possibility to limit, skip, sort and count the results. Let say we have following collection: To list the collection: Will return: To skip first 3 documents: Will return: To sort descending by the field name: Will return: If you want to sort ascending just replace -1 with 1 To count the results: Will return: Also combinations of this methods are allowed. For example get 2 documents from descending sorted collection skipping the first 1: Will return: |
| Query Document - Using AND, OR and IN Conditions All documents from Similar Similar AND Queries Similar Or Queries Similar And OR Queries Similar mySql Query of the above command. IN Queries This queries can improve multiple use of OR Queries Similar mySql query to above command |
| find() method with Projection The basic syntax of If you want to show all documents without the age field then the command is as follows If you want to show all documents the age field then the command is as follows |
| Find() method with Projection In MongoDB, projection means selecting only the necessary data rather than selecting whole of the data of a document. The basic syntax of If you want to to show all document without the age field then the command is as follows If you want to show only the age field then the command is as follows Note: Note: |
Read Article
https://develop.horje.com/learn/1434/reference