![]() |
VOOZH | about |
MongoDB, the most popular NoSQL database, we can get rows from the database by multiple columns conditionally from MongoDB Collection using the MongoDB collection.find() function with the help of $or or $and operators. The mongodb module is used for connecting the MongoDB database as well as used for manipulating the collections and databases in MongoDB.
collection.find() is the method of theMongoDBmodule in the node.js that is used to select the rows from the collections of a particular database present in the database of the MongoDB.
Syntax:
db.collection.find(query,projection)
Parameters: This method takes two parameters that are not required by default:
Return Type: The return type of this function is a JSON object.
$or or $and operators are used to apply multiple condition on the collection.
Installing Module: You can install the mongodb module using the following command:
node install mongodb
Project Structure: The project structure will look like the following.
👁 ImageRunning the server on Local IP: In the following command, data is the folder name.
mongod --dbpath=data --bind_ip 127.0.0.1👁 Image
MongoDB Database: Our database name and collection is shown below with some dummy data.
Database:GFG Collection:gfg2👁 Image
Filename: index.js
Run index.js file using below command:
node index.js
Output:
👁 Image