Node.js Inserting Documents


Example

For inserting a new document in the collection, we create a object of the schema.

var Auto = require('models/auto')
var autoObj = new Auto({
    name: "NewName", 
    countOf: 10
});

We save it like the following

autoObj.save(function(err, insertedAuto) {
    if (err) return console.error(err);
    insertedAuto.speak();
    // output: Hello this is NewName and I have counts of 10
});

This will insert a new document in the collection