I have a userAccounts Meteor Mongo database where I store the username and posts that the user has liked. This is how it looks:
userAccounts.insert({
username:Meteor.user().username,
likedPosts:{
postId:[this._id],
createdAt:new Date()
}
});
I want each time the user likes another post, to add the post._id to the postId in the likedPosts. So I did something like this:
userAccounts.update(
Meteor.user().username,{
$push:{
'likedPosts':{
'postId':this._id,
'createdAt':new Date()
}}
});
But for some reason it doesn't push the new post id to the array it just keeps the first record that was inserted above, so the insertion works. Any idea what I did wrong? Thanks in advance !