Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Node.js MongoDB Insert Record

Node.js MongoDB Insert Record

Posted on October 29, 2025October 29, 2025 By Rishabh saini No Comments on Node.js MongoDB Insert Record

Node.js MongoDB Insert Record

When working with Node.js and MongoDB, one of the most common tasks is inserting data into a collection. MongoDB provides simple methods like insertOne() and insertMany() to make this process quick and efficient. Let’s explore how to use these methods with practical examples.

Data Science Tutorial:–Click Here

Insert a Single Record

The insertOne() method is used to insert a single record into a MongoDB collection. The method takes an object as its first argument, where each key-value pair represents a field and its value in the document.

Example: Inserting a single record in the “employees” collection

Create a JavaScript file named insert.js, and add the following code:

var MongoClient = require('mongodb').MongoClient;  
var url = "mongodb://localhost:27017/MongoDatabase";  

MongoClient.connect(url, function(err, db) {  
  if (err) throw err;  
  var myobj = { name: "Ajeet Kumar", age: "28", address: "Delhi" };  
  db.collection("employees").insertOne(myobj, function(err, res) {  
    if (err) throw err;  
    console.log("1 record inserted");  
    db.close();  
  });  
});  

Now, open your terminal and run the following command:

Introduction to Applied AI:–Click Here

node insert.js

You’ll see the message “1 record inserted” in the console, which confirms that your record has been successfully added to the MongoDB collection.

Download New Real Time Projects :–Click here

Insert Multiple Records

To insert multiple records at once, MongoDB provides the insert() method (or the newer insertMany() method). This method accepts an array of objects, where each object represents a record you want to insert.

Example: Inserting multiple records in the “employees” collection

SQL Tutorial :–Click Here

Create a JavaScript file named insertall.js, and add the following code:

var MongoClient = require('mongodb').MongoClient;  
var url = "mongodb://localhost:27017/MongoDatabase";  

MongoClient.connect(url, function(err, db) {  
  if (err) throw err;  
  var myobj = [     
    { name: "Mahesh Sharma", age: "25", address: "Ghaziabad"},  
    { name: "Tom Moody", age: "31", address: "CA"},  
    { name: "Zahira Wasim", age: "19", address: "Islamabad"},  
    { name: "Juck Ross", age: "45", address: "London"}  
  ];  
  db.collection("employees").insert(myobj, function(err, res) {  
    if (err) throw err;  
    console.log("Number of records inserted: " + res.insertedCount);  
    db.close();  
  });  
});  

Run the script using the following command:

Deep Learning Tutorial:– Click Here

node insertall.js

After running this command, you’ll see an output indicating that multiple records have been successfully inserted into the collection.

Machine Learning Tutorial:–Click Here
Complete Advance AI topics:- CLICK HERE
Complete Python Course with Advance topics:-Click Here


how to insert data in mongodb using node js using mongoose mongodb insertone example how to insert data in mongodb compass mongodb insert document example search in node js mongodb mongodb insert one insertone mongodb nodejs insert multiple documents in mongodb compass node js mongodb insert record example node js mongodb insert record json mongodb insert using nodejs, how to insert data to mongodb using nodejs, how to insert thousands + records in mongodb, how i insert a data in mongodb node.js?, bulk insert in node js mongodb, insert into mongodb node js, insert data mongodb node js, node js insert data in mongodb, bulk insert in mongodb node js, nodejs mongodb api, mongodb nodejs, nodejs mongodb project, nodejs mongodb rest api, how to insert data to mongodb using nodejs and expressjs, nodejs mongodb crud, nodejs express mongodb crud

    Post Views: 248
    Node.js Tutorial Tags:bulk insert in mongodb node js, bulk insert in node js mongodb, how i insert a data in mongodb node.js?, how to insert data to mongodb using nodejs, how to insert data to mongodb using nodejs and expressjs, how to insert thousands + records in mongodb, insert data mongodb node js, insert into mongodb node js, mongodb insert using nodejs, mongodb nodejs, node js insert data in mongodb, nodejs mongodb api, nodejs mongodb crud, nodejs mongodb project, nodejs mongodb rest api

    Post navigation

    Previous Post: Best Hospital Management System using MERN Stack
    Next Post: Node.js MongoDB Select Record

    More Related Articles

    Node.js TLS SSL Node.js TLS SSL Node.js Tutorial
    Node.js Crypto Node.js Crypto Node.js Tutorial
    Node.js Net Node.js Net Node.js Tutorial

    Leave a Reply Cancel reply

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

    You may also like

    1. Install Nodejs on Windows
    2. Node.js Command Line Options
    3. Node.js Assertion Testing
    4. Node.js MySQL Update Records
    5. Node.js MySQL Delete Records
    6. Node.js MongoDB Filter Query

    Most Viewed Posts

    1. Top Large Language Models in 2025
    2. Online Shopping System using PHP, MySQL with Free Source Code
    3. login form in php and mysql , Step-by-Step with Free Source Code
    4. Flipkart Clone using PHP And MYSQL Free Source Code
    5. News Portal Project in PHP and MySql Free Source Code
    6. User Login & Registration System Using PHP and MySQL Free Code
    7. Top 10 Final Year Project Ideas in Python
    8. Blog Site In PHP And MYSQL With Source Code || Best Project
    9. Online Bike Rental Management System Using PHP and MySQL
    10. E learning Website in php with Free source code
    • AI
    • ASP.NET
    • Blockchain
    • ChatCPT
    • code Snippets
    • Collage Projects
    • Data Science Project
    • Data Science Tutorial
    • DBMS Tutorial
    • Deep Learning Tutorial
    • Final Year Projects
    • Free Projects
    • How to
    • html
    • Interview Question
    • Java Notes
    • Java Project
    • Java Script Notes
    • JAVASCRIPT
    • Javascript Project
    • JSP JAVA(J2EE)
    • Machine Learning Project
    • Machine Learning Tutorial
    • MySQL Tutorial
    • Node.js Tutorial
    • PHP Project
    • Portfolio
    • Python
    • Python Interview Question
    • Python Projects
    • PythonFreeProject
    • React Free Project
    • React Projects
    • Spring boot
    • SQL Tutorial
    • TOP 10
    • Uncategorized
    • Real-Time Medical Queue & Appointment System with Django
    • Online Examination System in PHP with Source Code
    • AI Chatbot for College and Hospital
    • Job Portal Web Application in PHP MySQL
    • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code

    Most Viewed Posts

    • Top Large Language Models in 2025 (8,618)
    • Online Shopping System using PHP, MySQL with Free Source Code (5,227)
    • login form in php and mysql , Step-by-Step with Free Source Code (4,879)

    Copyright © 2026 UpdateGadh.

    Powered by PressBook Green WordPress theme