In my collection Articles there is array field corrections with “copies” of articles.
Article object next to this:
{_id: 6369,
editedByUserId: "user1id",
staff: 'staff1',
corrections: [
{_id: 6369,
editedByUserId: "user2id",
staff: 'corrected_staff2'
},
{_id: 6369,
editedByUserId: "user3id",
staff: 'corrected_staff3'
}
]
}
I need to get one particular object from Articles.Corrections, by _id
and editedByUserId
For example, by passing _id=6369
and editedByUserId="user3id"
I expect object:
{_id: 6369,
editedByUserId: "user3id",
staff: 'corrected_staff3'
}
what I wanted is working in mongo shell with this expression:
db.articles.findOne({'_id': '6369', 'corrections.editedByUserId' : 'anonymous'}, {'corrections.$': 1}).corrections[0]
But when I tried make the same in meteor, I can’t get what I want.
doc = Articles.findOne({'_id': id, 'corrections.editedByUserId': correctionBy }, {fields: {corrections: 1, } } );
Code above returns whole array of corrections.
doc = Articles.findOne({'_id': id, 'corrections.editedByUserId': correctionBy }, {fields: {'corrections.$': 1, } } );
This code fires an error :
Exception in template helper: MinimongoError: Minimongo doesn’t support $ operator in projections yet.
I’m so tired, I tried hundred of combinations ( but still can’t figure out how to get one element from array…