Nodejs - Mongoose - callbacks work only once

214
June 09, 2017, at 3:53 PM

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

Answer 1

The server encountered an error. Your model is incorrectly exported, the right way :

var Modality = require('../models/modality').model('Modality').schema

READ ALSO
Error: Warning: Possible EventEmitter memory leak detected

Error: Warning: Possible EventEmitter memory leak detected

While running test I got warning using Postgresql

442
Running Node.js in Google Cloud Shell – Is it Free?

Running Node.js in Google Cloud Shell – Is it Free?

I'm very new to all of this, so please tell me anything I'm doing wrong!

184
Need help populating nesting arrays in mongoose

Need help populating nesting arrays in mongoose

I am struggling with populating nested arrays using mongoose

157
Node can't find module but it exists in node_modules?

Node can't find module but it exists in node_modules?

I've been playing with node for the past day and I've run into an issue I would really appreciate help on

215