How to retrieve the documents whose values ending with a particular character in mongoDB

Nithin K Anil picture Nithin K Anil · Feb 28, 2013 · Viewed 10.5k times · Source

I inserted the documents into a particular database in mongoDB. for example

 db.employee.insert({name:"nithin",age:22})
 db.employee.insert({name:"sreedevi",age:32})

now i wnat to retrive the documents whose name ending with character 'i'.

Answer

Sushant Gupta picture Sushant Gupta · Feb 28, 2013

In Javascript shell, use $regex operator

db.employee.find({name: {$regex: "i$"}})