Reputation: 133
I have the following data in my mongo database.
{
"FirstName": "Sunil",
"LastName": "Jamkatel"
}
I would like to add fullname to all the documents in the database such that it takes the firstname and lastname from a document and adds them up like:
{
"FirstName": "Sunil",
"LastName": "Jamkatel",
"FullName": "Sunil Jamkatel"
}
Please let me know the ways to do it using mongoosejs. Thanks
Upvotes: 1
Views: 704
Reputation: 444
One simple solution is to use a update with multi
option set to true
. The statement may look like:
YourModel.update(
{},
{
$set: {
"FullName": "Sunil Jamkatel"
}
},
{
multi: true
}
);
Upvotes: 1