0

Below is a screenshot of my mongo db collection.

i want to be able to find all record where the artist is Vónia Fernandes

after reading online i was able to get all entrys from 2008 with

db.eurovision.find({},{2008:1})

The screen show below returns nothing. Ive also tried putting Artist in quotes enter image description here

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
bpb101
  • 971
  • 1
  • 9
  • 18
  • Try `db.eurovision.find({"2008.Artist":"Vónia Fernandes"})` More here https://docs.mongodb.com/manual/tutorial/query-array-of-documents/ – s7vr Feb 07 '17 at 22:40
  • This returned the entire collection – bpb101 Feb 07 '17 at 22:44
  • You need to use `$filter` aggregation if you need to return all the matching entries for `Vónia Fernandes` in `2008.Artist` embedded array. Something like `db.eurovision.aggregate([ { $project: { artists: { $filter: { input: "$2008.Artist", as: "artist", cond: { $eq: [ "$$artist.Artist", "Vónia Fernandes" ] } } } } } ])` – s7vr Feb 07 '17 at 22:52
  • Possible duplicate of [How to filter array in subdocument with MongoDB](http://stackoverflow.com/questions/15117030/how-to-filter-array-in-subdocument-with-mongodb) – s7vr Feb 07 '17 at 22:56

1 Answers1

0

Try this:

db.eurovision.find({2008: {$elemMatch: {Artist:'Vonia Fernandes'}}})
Tanmay Verma
  • 263
  • 1
  • 3
  • 12