top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

MongoDB : How to insert a document in mongoDB without using the "insert" method ?

+2 votes
MongoDB : How to insert a document in mongoDB without using the "insert" method ?
posted Jul 12, 2015 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote

It is very simple to insert a document into a collection without using the insert method.

Take a variable by using the command var data = { } ** and assign multiples of (key:value) pairs to store data within it in such a way.
** = "alok"
data.age = 27
data.email_id = ""

Use the method "save" to insert or update the existing document in a collection. Here I assumed database name is "db", collection name is "employee".
Now issue following command

The command used above is used in place of insert method.

answer Jul 18, 2015 by Alok
pair should be in json form like
Similar Questions
+1 vote

Query description: I have a collection name student_db and added a document in a collection with entries (name: "alok, age : 31 and profession: "xyz"). After inserting the document into student_db database, I want to add another (key:value ) pair i.e. salary: 50000.

Can someone help me out to resolve this problem ?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.