Inserting Documents

suggest change

To insert a new document, create an instance of the model. Mongoose 6 removed the save callback; it returns a promise.

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

We save it like the following

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

This inserts a new document in the collection.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents