Reputation: 565
I have one SQL query written below :
Select * from student where fname + ' ' + lname like '%abc mno%';
How to write the same query in MongoDB?
Upvotes: 0
Views: 1178
Reputation: 2899
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
Upvotes: 0
Reputation: 7067
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'}})
Upvotes: 1