MongoDB: Search in array -


i have field in mongodb collection like:
{ place = ['london','paris','new york'] } need query return particular entry of array, specific character occurs. example, want search terms having letter 'o'(case-insensitive) in them. should return 'london' , 'new york'.
tried db.cities.find({"place":/o/i}), returns whole array.

you'll need $unwind using aggregate query, match.

db.cities.aggregate([ { $unwind:'$place' }, { $match: { place : {$regex: /o/i } } } ]) 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -