I'm trying to query for a specific element inside an array in a Meteor collection on the client side, but Minimongo doesn't support the $ operator. Is there an alternative to filter my query so it returns just the specific element in the array?
My collection is structured like this:
{
"userID": "abc123",
"array": [
{
"id": "foo",
"propA": "x",
"propB": "y"
},
{
"id": "bar",
"propA": "a",
"propB": "b"
}
]
}
I am trying to write a query that returns just the object in the array with id "foo". In Mongo, that query would be this:
collection.find({
"userID": "abc123",
"array.id": "foo"
}, {
"array.$": 1
});
However, Minimongo doesn't support the $ operator in projections so this throws an error. I've tried similarly structured queries using $elemMatch, and attempted the solution described here but it doesn't accomplish what I'm trying to do.
Is there an alternative means of querying for the one element in this array with Minimongo?