how to append data to a field in mongoose model
const {name , id} = req.body
Category.update(
{_id: id},
{$push: {items: {"name": name}}},{new: true, upsert: true }).exec();
res.sendStatus(200)exports.addFriend = function (req, res, next)
{
var friend = {"firstName": req.body.fName, "lastName": req.body.lName};
Users.findOneAndUpdate({name: req.user.name}, {$push: {friends: friend}});
};//mongoose appending data
var objFriends = { fname:"fname",lname:"lname",surname:"surname" };
Friend.findOneAndUpdate(
{ _id: req.body.id },
{ $push: { friends: objFriends } },
function (error, success) {
if (error) {
console.log(error);
} else {
console.log(success);
}
});
)
Also in JavaScript:
- moment format sql date
- nesting in Jinja2 expressions
- json.stringify pretty
- appendchild element once if element present in js
- how to convert seaconds into hh:mm:ss in javascript
- react js http post 500 internal server error
- js map constructor
- Lazy loading and code splitting in Vue.js
- javascript loop through arrya
- sort function in react js
- smaler div on devices
- filter in react native video
- antiforgerytoken mvc with ajax
- calculate width of text javascript
- in angular click button button hide div and show div
- parse tree for expression
- how to remove sub array null index in javascript
- how to get a toggle button to do different js functions
- device height react native
- append meta tag to head javascript
- array dia semana javascript
- how to add tooltip in angular for multiple items in an object
- return uncommon from two arrays js
- javascript repeat each second