Answers for "mongoose add document"

1

mongoose setup

// getting-started.js
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017/name", { useUnifiedTopology: true, useNewUrlParser: true });
Posted by: Guest on July-09-2020
3

create document mongoose

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) {

});
Posted by: Guest on December-12-2019
0

mongoose add document

const Product = require('../models/product.js');

const product = new Product();
product.save()
		.then(doc => {})
        .catch(err => {});
Posted by: Guest on March-23-2020

Code answers related to "mongoose add document"

Code answers related to "Javascript"

Browse Popular Code Answers by Language