Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
APPLIES TO:
MongoDB vCore
The $and
operator performs a logical AND operation on an array of expressions and selects the documents that satisfy all the expressions.
{ $and: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] }
Parameter | Type | Description |
---|---|---|
expression |
Array | An array of expressions that must all be true for a document to be included in the results |
Find stores with more than 10 full-time staff and more than 15 part-time staff:
db.stores.find({
$and: [
{ "staff.totalStaff.fullTime": { $gt: 10 } },
{ "staff.totalStaff.partTime": { $gt: 15 } }
]
})
Find stores that have total sales over 100000 and have both "Game Controllers" and "Home Theater Projectors" in their sales categories:
db.stores.find({
$and: [
{ "sales.totalSales": { $gt: 100000 } },
{ "sales.salesByCategory.categoryName": "Game Controllers" },
{ "sales.salesByCategory.categoryName": "Home Theater Projectors" }
]
})
Find stores that have promotional events in both June 2024 and September 2024 with discounts greater than 20%:
db.stores.find({
$and: [
{
"promotionEvents": {
$elemMatch: {
"promotionalDates.startDate.Month": 6,
"promotionalDates.startDate.Year": 2024
}
}
},
{
"promotionEvents": {
$elemMatch: {
"promotionalDates.startDate.Month": 9,
"promotionalDates.startDate.Year": 2024,
"discounts.discountPercentage": { $gt: 20 }
}
}
}
]
})
- Review options for Migrating from MongoDB to Azure Cosmos DB for MongoDB (vCore)
- Read more about Feature compatibility with MongoDB