vendredi 13 février 2015

Ember - Issue with HTTP POST request

I am new to Ember (among other things!). I have written a (very) simple RESTFul Web service to retrieve data from MongoDB using Node, Express and Mongoose.


On the server side, I have this code:



router.route('/products').post(function(req,res){
var product = new Product(req.body);
product.save(function(err){
if(err)
res.send(err);
res.send({message:'Product Added'});
});


When I submit a request from my Ember client, the req.body contains something like the following:



{ attributes:
{ category: 1,
name: 'y',
price: 1,
active: false,
notes: null } }


The attribute names are exactly the same as my mongoose schema. I get no error but the document created in MongoDB is empty (just get the _id and __v fields).


What am I doing wrong. Should I convert the req.body further into ??? Can you guys help me out?


Thanks.





Aucun commentaire:

Enregistrer un commentaire