How to push items into Mongo array via Mongoose?

Sometimes, we want to push items into Mongo array via Mongoose.

In this article, we’ll look at how to push items into Mongo array via Mongoose.

How to push items into Mongo array via Mongoose?

To push items into Mongo array via Mongoose, we can use the array push method.

For instance, we write

person.friends.push(friend);
person.save(done);

to call push on person.friends to append a new entry to the person‘s friends collection.

And then we call person.save to save the person entry.

Conclusion

To push items into Mongo array via Mongoose, we can use the array push method.