Node.js MongoDB Filter Query

In this tutorial you will learn about the Node.js MongoDB Filter Query and its application with practical example.

Node.js MongoDB Filter Query

While finding records in a MongoDB collection, you can pass search parameters using query object to filter the MongoDb result. The query object is used to limit the search result.

Example :- Let’s select records from “employees” collection where emp_name is “Keith”.

Step 1:- Let’s, create a node_mongo_filter.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 Filter With Regular Expression

Example :- Let’s select records from “employees” collection where emp_name starts with the letter “S”.

Step 1:- Let’s, create a node_mongo_filter_regex.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:-

 

 

In this tutorial we have learn about the Node.js MongoDB Filter Query and its application with practical example. I hope you will like this tutorial.