Friday 27 November 2020

Mongoose: Add more items to existing object

Using Mongoose, How can I add more items to an object without replacing existing ones?

 User.findOneAndUpdate(
  { userId: 0 },
  { userObjects: { newItem: value } }
 );

The problem with above code is that it clears whatever was there before and replaces it with newItem when I wanted it just to add another item to userObjects(Like push function for javascript arrays).



from Mongoose: Add more items to existing object

No comments:

Post a Comment