How to use insert Many in MongoDB

Mongo DB use BSON data instead of JSON . BSON for binary data. All we write in json & behind mongo DB use diver to convert JSON data to bson
insertMany command to use large no of data in the database collection. You can find a large no of sample data over here

I am using custom data

db.customers.insertMany([
  {
    "name": "Amit",
    "age": 29
  },
  {
    "name": "Amit Sharma",
    "age": 29
  },
  {
    "name": "Sumit",
    "age": 29
  },
  {
    "name": "Sumit Kumar",
    "age": 29
  },
  {
    "name": "Ashwin",
    "age": 29
  },
  {
    "name": "Ashwin kalara",
    "age": 29
  },
  {
    "name": "Mohit",
    "age": 29
  },
  {
    "name": "Mohit Khatree",
    "age": 29
  },
  {
    "name": "Vaibhav",
    "age": 29
  },
  {
    "name": "Vaibhav sharma",
    "age": 29
  },
  {
    "name": "Vaibhav Kaushik",
    "age": 29
  },
{
    "name": "Vaibhav vats",
    "age": 29
  },
  {
    "name": "Amit chauhan",
    "age": 29
  },
  {
    "name": "Amit kumar",
    "age": 29
  },
  {
    "name": "Amit chauhan",
    "age": 29
  },
  {
    "name": "Amit Json",
    "age": 29
  },
  {
    "name": "Amit panchal",
    "age": 29
  },
  {
    "name": "Vipul",
    "age": 29
  },
  {
    "name": "Vipul Shah",
    "age": 29
  },
  {
    "name": "Solanki",
    "age": 29
  },
  {
    "name": "Solanki Kumar",
    "age": 29
  },
  {
    "name": "Solanki Tiger",
    "age": 29
  },
  {
    "name": "Solanki Chauhan",
    "age": 29
  },
  {
    "name": "Suraj",
    "age": 29
  },
  {
    "name": "Suraj Rajput",
    "age": 29
  }
])

It will return acknowledgement or insertion as below

we cannot see all data at once you need it to command to view large data.

here is example

Get data as array we use toArray() with find as below

db.customers.find().toArray()

Now we get data in json array format

forEach Method in find

db.customers.find().forEach((customers)=>{printjson(customers)})

Returning only names.

find().preety() work as cursor

You may also like...

Leave a Reply

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

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

codeforbetter will use the information you provide on this form to be in touch with you and to provide updates and marketing.