Home » Node.js MongoDB Select Query

Node.js MongoDB Select Query

by Online Tutorials Library

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:

Node.js Select record 1


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:

Node.js Select record 2

You can see that all records are retrieved.

You may also like