0

I have one SQL query written below :

Select * from student where fname + ' ' + lname like '%abc mno%';

How to write the same query in MongoDB?

2
  • check this mongo sql mapping docs.mongodb.org/manual/reference/sql-comparison Commented Apr 7, 2015 at 13:35
  • This is an odd question, as presumably, your data in Mongo would be structured differently than in a relational database. Commented Apr 7, 2015 at 14:47

2 Answers 2

1
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'}})
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.