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
Post a Comment