user3386877
user3386877

Reputation: 565

Convert Sql Query into Mongodb Query

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

Answers (2)

Darshan Patel
Darshan Patel

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

Vishwas
Vishwas

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

Related Questions