top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

+2 votes
736 views
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 LinkedIn 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.
**data.name = "alok"
data.age = 27
data.email_id = "xyz@gmail.com"

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
db.employee.save(data)

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

answer Jul 18, 2015 by Alok
pair should be in json form like
{"data.name":"alok",
   "data.age":27,
   "data.email_id":"xyz@gmail.com"}
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 ?

...