how to insert multiple document in mongodb


How to insert multiple document in mongodb

save() method is use to insert multiple document in collection of mongodb.

db.stud.save([
{
    "roll" : 101,
    "name" : "Vikash Kumar",
    "addr" : "Hyderabad"
},
{
 "roll":101,
 "name":"Vikash Kumar",
 "addr":"Hyderabad"   
},
{
 "roll":102,
 "name":"Rahu; Kumar",
 "addr":"Hyderabad"   
},
{
 "roll":103,
 "name":"Rama Adlak",
 "addr":"Hyderabad"   
},
]
)

Retrive All Document

>db.stud.find()
/* 1 */
{
    "_id" : ObjectId("56e3d55e24f2c2611ca9c28b"),
    "roll" : 101,
    "name" : "Vikash Kumar",
    "addr" : "Hyderabad"
}

/* 2 */
{
    "_id" : ObjectId("56e3e06524f2c2611ca9c28d"),
    "roll" : 101,
    "name" : "Vikash Kumar",
    "addr" : "Hyderabad"
}

/* 3 */
{
    "_id" : ObjectId("56e3e06524f2c2611ca9c28e"),
    "roll" : 102,
    "name" : "Rahu; Kumar",
    "addr" : "Hyderabad"
}

/* 4 */
{
    "_id" : ObjectId("56e3e06524f2c2611ca9c28f"),
    "roll" : 103,
    "name" : "Rama Adlak",
    "addr" : "Hyderabad"
}

 






Full-stack web and mobile app development company Contact Us : Skype: indore.webcoder Email: info@w3sparks.com Sales: +91 8085506229