Kunok Kunok - 7 months ago 34
Node.js Question

Unable to push data into current object inside mongo database

I am using mongodb native and Node.js 6.5.0.

I have user object in mongodb which is structured as:

"_id" : ObjectId("57d7d294d96a73d128c46db9"),
"id" : "105862592064",
"labels" : [


I have a loop (for each user found) get data from API and then push it into object attribute of array type. Where user id
and data to push is

This is my code:


It doesn't return any error, neither it does update objects. What have I done wrong?


$push is for pushing a single element to an array. Use $push together with $each to push multiple elements. Also, quotes around the object labels should not be neccessary:

      { id:user.id },
      { $push: { labels: { $each: resp.labels } } }