85
Node.js MongoDB Select Record
The findOne() method is used to select a single data from a collection in MongoDB. This method returns the first record of the collection.
Example
(Select Single Record)
Select the first record from the ?employees? collection.
Create a js file named “select.js”, having the following code:
Open the command terminal and run the following command:
Select Multiple Records
The find() method is used to select all the records from collection in MongoDB.
Example
Select all the records from “employees” collection.
Create a js file named “selectall.js”, having the following code:
Open the command terminal and run the following command:
You can see that all records are retrieved.
Next TopicNode.js MongoDB Query