Tuesday 15 March 2011

Empty objects using app.post and AngularJS + mongoose on node.js -



Empty objects using app.post and AngularJS + mongoose on node.js -

my rest api posting empty objects.

i getting value req.body.name

if log console.log(req.body.name); value on console.

post: { name: 'typing name', status: null } typing name

so workflow between frontend (angular.js), form , backend (node.js, express, mongoose) seems work. post value, empty object in mongodb.

{"_id":"543a50a974de6e2606bd8478","__v":0}

app.post('/api/offers', function (req, res){ var offer; console.log("post: "); console.log(req.body); console.log(req.body.name); offer = new offermodel({ name: req.body.name, value: req.body.value, title: req.body.title, content: req.body.content, }); offer.save(function (err) { if (!err) { homecoming console.log("created offer" + req.body.name); } else { homecoming console.log(err); } }); homecoming res.send(offer); });

and here model:

var offerschema = mongoose.schema({ offer : { name : string, value : string, title : string, content : string, image : string, start : string, end : string, targets : string, beacons : string, published : string } }); var offermodel = mongoose.model('offer', offerschema);

schema incorrect, must this:

var offerschema = mongoose.schema({ name : string, value : string, title : string, content : string, image : string, start : string, end : string, targets : string, beacons : string, published : string });

node.js angularjs mongodb express mongoose

No comments:

Post a Comment