I am attempting to push data into a nested array inside of a Mongo collection. I've followed along the Mongo documentation here, http://docs.mongodb.org/manual/reference/operator/update/positional/, but have not had any luck pushing into the array. No errors or exceptions are thrown and the syntax looks right...
In this example, I'm attempting to update the buyer.boards titled 'Board One' by pushing a new string into it's idArr array. Is there something wrong with my query?
Mongo Collection
// User Document from Meteor.users Collection:
{
_id: 'userIdqwerty',
buyer: {
boards: [
{
title: 'Board One',
idArr: ['id123', 'id456', 'id678']
},
{
title: 'Board Two',
idArr: ['idABC']
},
{
title: 'Board Three',
idArr: ['id12345678', 'idqwertyuu']
},
]
};
}
Javascript
var options = {
boardTitle: 'Board One',
newId: 'idZjodFsp',
userId: 'userIdqwerty'
};
Meteor.users.update(
{
_id:options.userId,
'buyer.boards.$.title':options.boardTitle
},
{ $push: {
'buyer.boards.$.idArr':options.newId }
}
);