insert into collections in mongodb code example
Example 1: mongodb insert
db.products.insert( { item: "card", qty: 15 } )
Example 2: insert command mongo
db.collection.insert( { item: "card", qty: 15 } )
Example 3: mongo db const insertDocuments
const insertDocuments = function(db, callback) {
const collection = db.collection('documents');
collection.insertMany([
{a : 1}, {a : 2}, {a : 3}
], function(err, result) {
assert.equal(err, null);
assert.equal(3, result.result.n);
assert.equal(3, result.ops.length);
console.log("Inserted 3 documents into the collection");
callback(result);
});
}