push an element to an array in a mongoose document

10 views
Skip to first unread message

Saiteja Parsi

unread,
Oct 1, 2014, 11:05:07 AM10/1/14
to mongoos...@googlegroups.com


My schema is as follows:

var schema = new mongoose.Schema({
_id: String,
name:String,
to:[{
   name: String,
   message: [{
      content: String
      timestamp: Date
            }]
   }]
});

I need to push the {content: Content, timeStamp: timestamp} to the message array where to.name == "someName".

I tried in this way but could not succeed.Please help me.

User
  .find({_id: id})
  .where('to.name').equals("someName")
  .to.message.push({content: Content, timeStamp: timestamp})
  .exec(function(err, doc){
            if(err) return console.log(err);
            console.log(doc);
        });
Reply all
Reply to author
Forward
0 new messages