a) db.collection.insert() - Version 2.6
1 2 3 4 5 6 7 8 9 10 11 |
db.products.insert( { name: "Coding 4 Developers", email: "info@coding4developers.com" } ) db.products.insert( [ { item: "Wingy Kart", qty: 15 }, { item: "Wingy Kart", qty: 20 }, { item: "Wingy Kart" , qty: 30 } ] ); |
b) db.collection.save() - Version 2.6
The save() method uses either the insert or the update command. If record already exit the it updates else insert the new document.
1 |
db.products.save( { item: "Wingy kart", qty: 20 } ) |
c) db.collection.insertOne() - Version 3.2
1 2 3 4 5 6 |
db.user.insertOne( { name: "Coding 4 Developers", email: "info@coding4developers.com" } ) |
d) db.collection.insertMany() - Version 3.2
1 2 3 4 5 |
db.products.insertMany( [ { item: "Wingy Kart", qty: 15 }, { item: "Wingy Kart", qty: 20 }, { item: "Wingy Kart" , qty: 30 } ] ); |