add in to array mongoose
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);
}
});
)// With { $push: { field: element } }
// Example:
const elementToPush = { a: 1, b: 2 };
const body = { $push: { arrayField: elementToPush } };
model.patch(id, body);
Also in JavaScript:
- how can we take selected index value of dropdown in javascript
- nodemon : The term 'nodemon' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + nodemon index
- json token for .ini file
- eliminare spazi inizio e fine stringa javascript
- escape in javascript
- json unmarshal golang example
- how to add array numbers in javascript
- parameters types in javascript
- Material-ui account tree icon
- regex special characters javascript
- knex insert multiple rows
- mongoose find and update prop
- nextjs svg npm
- isDate javascript
- return an object from an array javascript
- install react native
- how to made disktop program on react website
- download .json file
- Sum of all the multiples of 3 or 5
- javascript array loop
- curren route vue
- chamar arquivo javascript no html
- import json file javascript
- ip my adress