MongoDB Insert Multiple Documents - Java @ Desk

Sunday, May 18, 2014

MongoDB Insert Multiple Documents

MongoDB Insert Multiple Documents

In our last post, we learn how to Insert Document in MongoDB. In this post, we will learn to insert multiple documents at once.

db.loans.insert(
   [
     { <RECORD> },
     { <RECORD> },
     { <RECORD> }
   ]
)


This will insert 3 records in the collection loans.

db.loans.insert(
   [
     { { item: "home", interest: 10 } },
     { { _id: 10, item: "personal", interest: 14 } }
   ]
)


This will insert 2 records in the collection loans and in 1st case it will create unique ObjectId. Following records will be inserted

{ <b>"_id" : ObjectId("51e0373c6f35bd826f47e9a0")</b>, item: "home", interest: 10 } 
{ _id: 10, item: "personal", interest: 14 }







No comments:

Post a Comment