
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
Query for multiple parameters in MongoDB?
To query for multiple parameters in MongoDB, you can use the dot(.) notation. Let us first create a collection with documents −
> db.multipleParametersDemo.insertOne( ... { ... "CustomerName" : "Larry", ... "CustomerDetails" : [ ... { ... "CustomerCountryName" : "US", ... "CustomerBankName" : "HDFC", ... "CustomerBalance" : 17363, ... } ... ], ... "Purchase" : 1456, ... ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cd10f9ce3526dbddbbfb60a") }
Following is the query to display all documents from a collection with the help of find() method −
> db.multipleParametersDemo.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5cd10f9ce3526dbddbbfb60a"), "CustomerName" : "Larry", "CustomerDetails" : [ { "CustomerCountryName" : "US", "CustomerBankName" : "HDFC", "CustomerBalance" : 17363 } ], "Purchase" : 1456 }
Following is how you can query for multiple parameters in MongoDB −
> db.multipleParametersDemo.find({CustomerName: 'Larry', 'CustomerDetails.CustomerCountryName': 'US'}).count();
This will produce the following output −
1
- Related Articles
- MongoDB query for exact match on multiple document fields
- MongoDB query to add multiple documents
- Update multiple rows in a single MongoDB query?
- Search multiple fields for multiple values in MongoDB?
- Fetch multiple documents in MongoDB query with OR condition?
- Search for multiple documents in MongoDB?
- MongoDB query to pull multiple values from array
- MongoDB query to $pull / $unset with multiple conditions?
- Query to retrieve multiple items in an array in MongoDB?
- Multiple COUNT() for multiple conditions in a single MySQL query?
- MongoDB query for exact match
- MongoDB query for array concatenation?
- MongoDB query to check the existence of multiple fields
- What is the syntax for input parameters (variables) in a MySQL query?
- MongoDB query to find value in array with multiple criteria (range)

Advertisements