$set no mongoose code example
Example 1: create document mongoose
var Tank = mongoose.model('Tank', yourSchema);
var small = new Tank({ size: 'small' });
small.save(function (err) {
if (err) return handleError(err);
});
Tank.create({ size: 'small' }, function (err, small) {
if (err) return handleError(err);
});
Tank.insertMany([{ size: 'small' }], function(err) {
});
Example 2: findone and update mongoose
Model.findOne({ name: 'Mr. Anderson' }).
then(doc => Model.updateOne({ _id: doc._id }, { name: 'Neo' })).
then(() => Model.findOne({ name: 'Neo' })).
then(doc => console.log(doc.name));
const doc = await Model.findOne({ name: 'Neo' });
console.log(doc.name);