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 schema = new mongoose.Schema({ name: 'string', size: 'string' });
2const Tank = mongoose.model('Tank', schema);
1const modelName = mongoose.model("collectionname", collectionSchema);
2
3//example
4const fruitSchma = new mongoose.Schema ({
5 name: String
6});
7const Fruit = mongoose.model("Fruit", fruitSchema);
1const Tank = mongoose.model('Tank', yourSchema);
2
3const 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});
1mongoose.connect('mongodb://localhost/gettingstarted', {useNewUrlParser: true,useUnifiedTopology: true});