Skip to content Skip to sidebar Skip to footer

Mongodb Select And Concatenate Fields

I have a very basic question: SELECT name, surname CONCAT(name, surname) AS name_surname from users; How can I convert this SQL to MongoDB query? During my search, I have decided

Solution 1:

Use the aggregation operations as below:

db.collection.aggregate([
{$project:{"name_surname":{$concat:["$name","-","$surname"]},"name":1,"surname":1}}
])

Post a Comment for "Mongodb Select And Concatenate Fields"