Categories
JavaScript Answers

How to push items into Mongo array via Mongoose?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *