How to push data in a MongoDB document ? Last Updated : 15 Jun, 2022 Comments Improve Suggest changes Like Article Like Report The insertOne() and insertMany() are the two methods of the MongoDB module in node.js that are used to push the documents in the collections of the MongoDB database. The insertOne() method inserts one data at a time into the collection and insertMany() method inserts multiple data into the collection of the MongoDB database. In this article, we will discuss how to push data in MongoDB collection using MongoDB module methods. Installing module: You can install mongodb module using the following command. node install mongodbProject Structure: It will look like the following. Running Server on Local IP: Data is the directory where MongoDB server is present. mongod --dbpath=data --bind_ip 127.0.0.1 index.js const MongoClient = require("mongodb"); // Server running const url = 'mongodb://localhost:27017/'; // Database name const databasename = "GFG"; MongoClient.connect(url).then((client) => { // Connecting to the database const connect = client.db(databasename); // Database collection const collection = connect .collection("GFGcollections"); // Inserting single document collection.insertOne({ "name": "aayush", "class": "GFG" }); // Inserting multiple document collection.insertMany([ { "name": "saini", "class": "GFG" }, { "name": "GfGnew", "class": "GFGNEW" } ]); console.log("Insertion Successful") }).catch(err) => { // If error occurred show the error message console.log(err.Message); } Run index.js file using the following command: node index.jsOutput: MongoDB Database: Comment More infoAdvertise with us Next Article How to push data in a MongoDB document ? Z zack_aayush Follow Improve Article Tags : Web Technologies Node.js MongoDB Node.js-Methods NodeJS-Questions +1 More Similar Reads How to Push Item From an Array in Mongoose? Mongoose, an Object Data Modeling (ODM) library for Node.js and MongoDB, makes database interactions easier through a comprehensive API. One of the most frequent operations that developers execute using Mongoose is adding an item to an array of a document. In this article, we will discuss the differ 6 min read How to Update the _id of MongoDB Document? In MongoDB, the _id field serves as a unique identifier for each document in a collection. While MongoDB automatically generates _id values for documents upon insertion, there are scenarios where we might need to update the _id of a document. In this article, We will learn about How to update the _i 3 min read How Many Documents are in a MongoDB Collection? In MongoDB, data is organized into collections and documents. A collection is a grouping of documents similar to a table in a relational database but without a fixed schema it allowing for flexible data structures. Documents on the other hand are JSON-like structures composed of key-value pairs whic 6 min read How to Get Data from MongoDB using Node.js? One can create a simple Node.js application that allows us to get data to a MongoDB database. Here we will use Express.js for the server framework and Mongoose for interacting with MongoDB. Also, we use the EJS for our front end to render the simple HTML form and a table to show the data. Prerequisi 6 min read MongoDB CRUD Operations: Insert and Find Documents MongoDB is a NoSQL database that allows for flexible and scalable data storage using a document-based model. CRUD (Create, Read, Update, Delete) operations form the backbone of any database interaction and in MongoDB, these operations are performed on documents within collections. In this article, w 3 min read Like