1// getting-started.js
2const mongoose = require('mongoose');
3mongoose.connect("mongodb://localhost:27017/name", { useUnifiedTopology: true, useNewUrlParser: true });
1var Tank = mongoose.model('Tank', yourSchema);
2
3var small = new Tank({ size: 'small' });
4small.save(function (err) {
5 if (err) return handleError(err);
6 // saved!
7});
8
9// or
10
11Tank.create({ size: 'small' }, function (err, small) {
12 if (err) return handleError(err);
13 // saved!
14});
15
16// or, for inserting large batches of documents
17Tank.insertMany([{ size: 'small' }], function(err) {
18
19});
1const Product = require('../models/product.js');
2
3const product = new Product();
4product.save()
5 .then(doc => {})
6 .catch(err => {});