I have one SQL query written below :
Select * from student where fname + ' ' + lname like '%abc mno%';
How to write the same query in MongoDB?
db.collection.find({"name":/.*abc mno.*/})
OR
db.collection.find({"name":/abc mno/})
You can also use mongo regex
db.collection.find({"name":{'$regex': 'abc mno'}})
Please find below examples,
db.student.find({name:{$regex:"a"}}) //Contain a anywhere
or
db.student.find({name:{$regex:"e$"}}) //Ends with e
or
db.student.find({name:{$regex:"^A"}}) //Start with A
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.