Mongodb concatenation

How to replace SQL concatenation in mongoDB

 

example  in SQL:

SELECT CONCAT(firstName, ” “, lastName) AS fullName
FROM Customers WHERE concat(firstName, " ", lastName) = 'value'

;

 

MongoDB:

in below 3.6

db.coll.aggregate({$match:{firstName:/^val/}},
                  {$project:{newField:{$concat:["$firstName","$lastName"]}}},
                  {$match:{newField:"value"}} 
);

please consider to index firstName, wich will improve performance .

in 3.6 or above  :

db.coll.find({$expr:{$eq:["value", {$concat:["$firstName", "$lastName"]}]}})