MongoDB Insert Document-ProgrammersHelper


MongoDB insert document

This article will provide step by step basic concept of MongoDB.where you can easily understand the core concept of MongoDB.<db.collection.insert()> method is used to insert data into a collection.if the collection does not exist then insert method is used to create a collection.All the data stored in a collection are Bison format.


It would be better if you have the basic knowledge of RDBMS concept. Actually, you are going to learn a high-performance database so we need some basics of these.It will good to cover my below articles before this.Its help to learn more about MongoDB.In which I explained.Click here  MongoDB Collection Creation Guideline and MongoDB Relationship step by step Guideline.

Implementation Section

  • Insert Method( )
  • Multipal document insert Method( )
  • The Insertone Method ()

Insert Method ( )


  • <db> is a reserved word.
  • <Collection_name> writes the collection name.
  • <Insert> is also keyword used for insert data into the collection.
  • Inside the bracket write the <document>.


Simple like following.

db<collection_name>insert({“name”: “ABC”, “age”: 24, “gender”: “male”})

Practical example

You do not confuse MongoDB insert document.I configure MongoDB command prompt shell into IntelliJ IDEA.Next post I will show details how to configure it.

Alt tag MongoDB insert document

Multiple document insert ( )
  • For Multiple record ({[ write JSON data]})
     For insert multiple documents. you want to use an array [ ] or array object to insert multiple documents in a collection.this same like insert a single record.but use array object [ ].this is simple code below which consist multiple documents. I simply add into logs database.

Output: In which above code adds.

Alt MongoDB insert document

Insert one Method ()


If you want to insert a single document then the best thing to use insert one Method ().The simple syntax you just use insert one like below.

You just see in below pic.Output:

Alt tag MongoDB insert document


I wish I could tell you that a great site of just understands key element above post-MongoDB insert document.Click here More detail How can insert the document in MongoDB. I hope you will understand this lecture.Thank you for reading this lecture. Hope you got the idea. please share it.