Thursday 8 June 2017

Nodejs - Mongoose - callbacks work only once

I am working with callbacks, and it makes the first call (POST| GET) and never work again (could not get any response error in postman) this is the modal schema :

var mongoose = require('mongoose'); 
mongoose.Promise = require('bluebird'); 
var ModalitySchema = new mongoose.Schema({   
    name: {
    type: String,
    unique: true,
    required: true
  },
  type: {
    type: String,
    required: true
  },
    updated_at: { type: Date, default: Date.now },
  created_at: { type: Date, default: Date.now }
});

And this is the call in the controller :

var mongoose = require('mongoose');
var Modality = require('../models/modality').Modality;

/** create function to create Modality. */
exports.create = function (req, res) {
Modality =new Modality({name:req.body.name,type: req.body.type});  
Modality.save( function(err, result) {
        if (!err) {
            return res.json(result);
        } else {
          console.log(err);

            return res.send(err); // 500 error
        }
    });
};

and the outers of node Outer of node



via ketimaBU

No comments:

Post a Comment