MongoDB - finding entries using a nested dictionary

纵饮孤独 提交于 2020-12-05 10:30:09

问题


I have a MongoDB that I use with python. My entries that looks as follows:

{
   a: something
   b: something
   c: {
        d: something
        e: something
        f: something
       }
}

I want to query for entries that have a specific values for d and e but I don't care about the value in f.

I tried not specifying f at all (similarly to when I don't care about the b value where I just not adding it to the query):

{
   a: a_value
   b: b_value
   c: {
        d: d_value
        e: e_value
       }
}

I also tried to use:

{
   a: something
   b: something
   c: {
        d: something
        e: something
        f: { $exists : 1 }
       }
}

but none of these worked (in fact, I got no results at all)

How my query shall look like?

thanks!


回答1:


I found the solution. The query shall look as follows:

{
   a: something
   b: something
   c.d: something
   c.e: something
}

I hope it helps someone :-)



来源:https://stackoverflow.com/questions/45138086/mongodb-finding-entries-using-a-nested-dictionary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!