I have the following collection
[
{"overlaps": [{"BB1": "itemA", "iou": 0.1, "BB2": "itemB"},{"BB1": "itemB", "iou": 0.4, "BB2": "itemC"}], "City": "Paris", "mode": "RGB","path": "photo1.png"},
{"overlaps": [{"BB1": "itemA", "iou": 0.5, "BB2": "itemC"}], "City": "London", "mode": "RGB","path": "photo2.png"},
{"overlaps": [{"BB1": "itemB", "iou": 0.8, "BB2": "itemB"}], "City": "London", "mode": "greyscale","path": "photo3.png"},
{"overlaps": [{"BB1": "itemA", "iou": 0.2, "BB2": "itemC"},{"BB1": "itemA", "iou": 0.8, "BB2": "itemC"}], "City": "Berlin", "mode": "RGB","path": "photo4.png"},
{"overlaps": [{"BB1": "itemA", "iou": 0.9, "BB2": "itemB"}], "City": "NY", "mode": "greyscale","path": "photo5.png"},
{"overlaps": [{"BB1": "itemA", "iou": 0.8, "BB2": "itemB"}], "City": "Roma", "mode": "RGB","path": "photo6.png"}
]
I would like to retrieve documents that
have city = berlin
OR have mode = greyscale
OR countains at least one overlap between "BB1":"itemA" and "BB2":"itemC"
The first 2 conditions are easy:
cursor = record1.find({"$or": [{"City":"Berlin"},{"mode":"greyscale"}]})
How can I add the third condition to the query?
You should need to apply $elemMatch
with $or
condition to obtain the result
db.collection.find({
$or: [{ City: "Berlin" }, { mode: "greyscale" },
{
overlaps: {
$elemMatch: {
$or: [
{
BB1: "itemA",
BB2: "itemC"
}
]
}
}
}
]
})
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments