nodejs mongoose model 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: model mongoose
const modelName = mongoose.model("collectionname", collectionSchema);
const fruitSchma = new mongoose.Schema ({
name: String
});
const Fruit = mongoose.model("Fruit", fruitSchema);