Inserting Documents
suggest changeTo 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents