
- 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
Select multiple values with MongoDB OR operator
Let us first create a collection with documents −
> db.demo270.insertOne({"ClientName":"Chirs","Age":34}); { "acknowledged" : true, "insertedId" : ObjectId("5e481e371627c0c63e7dbab8") } > db.demo270.insertOne({"ClientName":"David","Age":31}); { "acknowledged" : true, "insertedId" : ObjectId("5e481e3d1627c0c63e7dbab9") } > db.demo270.insertOne({"ClientName":"Bob","Age":31}); { "acknowledged" : true, "insertedId" : ObjectId("5e481e431627c0c63e7dbaba") } > db.demo270.insertOne({"ClientName":"Carol","Age":36}); { "acknowledged" : true, "insertedId" : ObjectId("5e481e491627c0c63e7dbabb") }
Display all documents from a collection with the help of find() method −
> db.demo270.find();
This will produce the following output −
{ "_id" : ObjectId("5e481e371627c0c63e7dbab8"), "ClientName" : "Chirs", "Age" : 34 } { "_id" : ObjectId("5e481e3d1627c0c63e7dbab9"), "ClientName" : "David", "Age" : 31 } { "_id" : ObjectId("5e481e431627c0c63e7dbaba"), "ClientName" : "Bob", "Age" : 31 } { "_id" : ObjectId("5e481e491627c0c63e7dbabb"), "ClientName" : "Carol", "Age" : 36 }
Following is the query to select multiple values with OR operator −
> db.demo270.find({ ... "$or" : [ ... { ... "ClientName" : "Carol" ... }, ... { ... "Age" : 31 ... } ... ] ...} ...);
This will produce the following output −
{ "_id" : ObjectId("5e481e3d1627c0c63e7dbab9"), "ClientName" : "David", "Age" : 31 } { "_id" : ObjectId("5e481e431627c0c63e7dbaba"), "ClientName" : "Bob", "Age" : 31 } { "_id" : ObjectId("5e481e491627c0c63e7dbabb"), "ClientName" : "Carol", "Age" : 36 }
- Related Articles
- Find values with OR operator in MongoDB and format the result.?
- MongoDB to fetch documents with $or Operator
- MySQL Select Multiple VALUES?
- JavaScript merge multiple Boolean arrays with the OR || operator
- Search multiple fields for multiple values in MongoDB?
- Fetch multiple documents in MongoDB query with OR condition?
- MySQL query to return multiple row records with AND & OR operator
- Update values in multiple documents with multi parameter in MongoDB?
- How to implement MongoDB $or operator
- How to select documents with values above the average in MongoDB?
- MongoDB pull with positional operator?
- MongoDB query to get documents with multiple conditions set in $or?
- MongoDB query to implement OR operator in find()
- MySQL select query with multiple WHERE?
- MongoDB multiple OR conditions on same key?

Advertisements