Reputation: 577
I have a collection where each document contains an embedded collection; for example:
{
cells: [
{
x: 1,
y: 2
},
{
x: 3
}
]
/* more fields not shown */
}
Is there a way to find those documents that have at least one document in the cells collection without a y-value (like the record shown here)?
Upvotes: 1
Views: 41
Reputation: 7748
You could use $elementMatch to achieve it:
db.col.find({
cells: {
$elemMatch: {
y: {
$exists: false
}
}
}
});
Upvotes: 3