Q:

mongoose model

const schema = new mongoose.Schema({ name: 'string', size: 'string' });
const Tank = mongoose.model('Tank', schema);
4
var Tank = mongoose.model('Tank', yourSchema);

var small = new Tank({ size: 'small' });
small.save(function (err) {
  if (err) return handleError(err);
  // saved!
});

// or

Tank.create({ size: 'small' }, function (err, small) {
  if (err) return handleError(err);
  // saved!
});

// or, for inserting large batches of documents
Tank.insertMany([{ size: 'small' }], function(err) {

});
1
const modelName = mongoose.model("collectionname", collectionSchema);

//example
const fruitSchma = new mongoose.Schema ({
  name: String
});
const Fruit = mongoose.model("Fruit", fruitSchema);
1
mongoose.connect('mongodb://localhost/gettingstarted', {useNewUrlParser: true,useUnifiedTopology: true});
0

Tags

New to Communities?

Join the community