javascript - Meteor Restivus - POST body (JSON) to mongoDB -


my code looks this. post action in restivus. 'subs' mongodb collection.

post: {       authrequired: false,       action: function () {         var tmp = subs.insert(this.bodyparams);         if(tmp){           return tmp;         }         return {           statuscode: 400,           body: {status: 'fail', message: 'unable create subscriber!'}         };       }     } 

when send json data in body, example:

{ _id: 1, name: "john", lastname: "smith" } 

in mongodb new document created, random (default notation) string , without data sent. guess data not parsed right.

does know why happens? should function format json before passing mongodb body?

try ... insert {status: 'success', data: tmp};.

post: {   authrequired: false,   action: function () {     var tmp = subs.insert(this.bodyparams);     if(tmp){       return {status: 'success', data: tmp};     }     return {       statuscode: 400,       body: {status: 'fail', message: 'unable create subscriber!'}     };   } } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -