Skip to content Skip to sidebar Skip to footer

How To Add New Objects Inside Nested Array For Mongodb Using Node.js?

I have the following database structure stored in the mongoDB: 'location' : 'Halifax', 'students' : [ { 'name': 'Mike', 'ID': 'B00123456', 'imag

Solution 1:

The update() function is

 update(selector, document[, options][, callback])

The first parameter is selector, please try this one

var student_name = req.body.name;
    var student_id = req.body.ID;
    collection.update( 
             { location:"Halifax", 
               'students.ID': student_id, 
               'students.name': student_name},
             {$push: { "students.$.images": 
                                {
                                    "image_url":"www.example.com",
                                    "image_id":"uqxhqbxqx_1219"
                                }
                     }
     }, function(err,result){

Post a Comment for "How To Add New Objects Inside Nested Array For Mongodb Using Node.js?"