Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In MongoDB, the following types of queries can be performed using both AND and OR operators:

  1. Simple queries: You can use the AND or OR operators to combine multiple conditions in a query.

Example: db.collection.find( { $or: [ { status: "A" }, { qty: { $lt: 30 } } ] } )

  1. Nested queries: You can use the AND or OR operators to combine multiple conditions in a nested query.

Example: db.collection.find( { $and: [ { "author": "John Doe" }, { $or: [ { "category": "fiction" }, { "category": "non-fiction" } ] } ] } )

  1. Range queries: You can use the AND or OR operators to combine multiple range conditions in a query.

Example: db.collection.find( { $and: [ { age: { $gt: 18 } }, { age: { $lt: 30 } } ] } )

  1. Regular expression searches: You can use the AND or OR operators to combine regular expressions in a query.

Example: db.collection.find( { $or: [ { name: /^A/ }, { name: /e$/ } ] } )