mongoosejs docs code example
Example 1: how to install mongoose
$ npm install mongoose
Example 2: 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 3: mongoose add document
const Product = require('../models/product.js');
const product = new Product();
product.save()
.then(doc => {})
.catch(err => {});
Example 4: mongoose max record
const maxQuery = Goods.find({}).sort({ price: -1 }).limit(1).then(goods => goods[0].price);