1

I'm using waterline ORM to insert a new user data in mongo DB. This is the code from my controller action.

function *(){
    var self = this;
    var attributes= this.request.body
    var userModel = this.models.user;

    userModel.create(attributes).exec(function(err, model){
        self.type = 'application/json';
        self.body = {success:true,description:"user Created"};
    });
}

When I try to execute a request I have the following error:

...../node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/connection/base.js:245
    throw message;      
          ^
Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:331:11)

I'm not an expert with Koa but I think that it is because this is an async process and the answer message was written before.

Can anyone help me?? I'm very interested to understand this technology.

4

1 に答える 1