so I have this document that im trying to update the comments on and when I do so, it seems to overwrite the array with the new information coming in. Any idea why?
Confession.findOne({_id: confessionID}, function (err, confession) {
if (err){
console.log(err);
} else {
confession.update(
{$pushAll: {'comments.commentData':
[{comment: req.body.text, commenter: req.body.name }]
}},
{upsert: true},
function (err, confession) {
if (err) {
console.log(err);
} else {
res.send(confession.comments);
console.log(confession);
}
});
}
Here is a sample document as requested
{ "__v" : 0,
"_id" : ObjectId( "5171c2bd47a7510000000002" ),
"absolves" : { "IDs" : [ null ],
"num" : 2 },
"comments" : { "commentData" : [
{ "comment" : "asdfas wdfwe cqwe qwe w w",
"_id" : ObjectId( "5179c9fa79c165e74d000002" ),
"timeStamp" : Date( 1366936058266 ) }],
"num" : 0 },
"condemns" : { "IDs" : [ null ],
"num" : 2 },
"facebook" : 1232876940,
"removed" : false,
"text" : " another confession",
"time" : Date( 1366409917817 ) }
Try this
{$push: {'comments.commentData':
{comment: req.body.text, commenter: req.body.name }
}},