Nodejs MongoDB Find Record

Node.js MongoDB Find Record

The findOne() method is used to select a single record from a MongoDB collection. It returns the first record in the given collection.

Example :- Let’s select a single record from  “employees” collection.

Step 1:-  Let’s, create a node_mongo_findone.js file and put the following code in it –

Step 2:- Save the code and open the terminal again, and type the following command in order to run the file.

you will see following output on terminal –

Output:-

Node.js MongoDB Select Multiple Record

The find() method is used to select all records from a MongoDB collection. It returns the all record in the given collection.

Example :- Let’s select all record from  “employees” collection.

Step 1:-  Let’s, create a node_mongo_find.js file and put the following code in it –

Step 2:- Save the code and open the terminal again, and type the following command in order to run the file.

you will see following output on terminal –

Output:-