generators/app/templates/server/lib/controllers/crud.controller.js
function (req, res) {
    var self = this;

    var populations = self.filterPopulations('create');

    this.model.populate(req.body, populations, function (err, populated) {
      if (err) {
        return res.handleError(err);
      }

      self.model.create(populated, function (err, document) {
        if (err) {
          return res.handleError(err);
        }
        populated._id = document._id;

        return res.created(self.getResponseObject(populated));
      })
    });
  }
function (req, res) {
    var self = this;

    var populations = self.filterPopulations('create');

    this.model.populate(req.body, populations, function (err, populated) {
      if (err) {
        return res.handleError(err);
      }

      self.model.create(populated, function (err, document) {
        if (err) {
          return res.handleError(err);
        }
        populated._id = document._id;

        return res.created(self.getResponseObject(populated));
      })
    });
  }
function ( req , res ) { var self = this ; var populations = self . filterPopulations ( 'create' ) ; this . model . populate ( req . body , populations , function ( err , populated ) { if ( err ) { return res . handleError ( err ) ; } self . model . create ( populated , function ( err , document ) { if ( err ) { return res . handleError ( err ) ; } populated . _id = document . _id ; return res . created ( self . getResponseObject ( populated ) ) ; } ) } ) ; }
Creates a new document in the DB.
@param {IncomingMessage} req - The request message object containing the json document data
@param {ServerResponse} res - The outgoing response object
@returns {ServerResponse} The response status 201 CREATED or an error response
Creates a new document in the DB .