1

I have the following insert on MongoDB.

db.country.insert({
    "name":{"common":"Madrid"},
    "currency":["EUR"],
    "languages":{"mad":"Madrid","spa":"Spanish"},
    "region":"Europe"
})

I want to find that entry if Madrid is inside languages with a find, but I don't know how to perform a query like that. I've been searching for it, but I didn't find any solution that is working for me.

1
  • Your model doesn't seem adapted for what you want to achieve. A more sensible query would be to check if mad exists in the languages object, which you can do with find({'languages.mad': {$exists: true}}). Also, is there a reason for languages not being an array?
    – sachav
    Dec 9, 2018 at 22:43

0

Your Answer

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

Browse other questions tagged or ask your own question.