mongodb Error mongoose do not push object in array $pushAll
Try using findOneAndUpdate
instead.
User.findOneAndUpdate( { name: "gino" }, { $push: { posts: { title: 'post', content: 'content' } } }, { new: true }, function (err, user) { if(err) console.log("Something wrong when updating data"); console.log(user); });
Hope it helps!
If you are using 3.5 MongoDB version or higher, can be an issue with $pushAll, which is deprecated.I founded an option to work around setting usePushEach to true:
new Schema({ arr: [String] }, { usePushEach: true });
Founded in:
https://github.com/Automattic/mongoose/issues/5574#issuecomment-332290518
Can be useful to use the with .push.