Reputation: 535
I am using POST query to save data in my app. How can I add additional params to Item
? I want to add something like user: req.user._id
.
var Item = new Model(req.body);
Item.save(function (err, model) {
res.send(model);
});
So my document will look like:
{
param1: '1',
param2: '2',
user: ObjectID('blahblahblah')
}
From my form I got two params - param1
and param2
. user
parameter was added before saving the document.
Upvotes: 0
Views: 42
Reputation: 151142
Assuming what you mean is adding something additional that is not in the form, then it is just a JavaScript object so there is nothing wrong with this:
req.body.userId = "Me";
And now req.body
contains your new property that you can pass into your other constructor or even directly save. Try it in a REPL or with console.log
Upvotes: 1