mongodb $exists always returning 0

后端 未结 2 1614
面向向阳花
面向向阳花 2020-12-11 17:38

I have a database collection (named fols) like so:

{\'followers\':
        {
           \'123\':1
           \'123\':2
           \'123\':3
         }
}


        
相关标签:
2条回答
  • 2020-12-11 17:56

    When you're not matching a complete object you need to use dot notation to use an operator against an embedded object. So in this case:

    cursor = fols.find({'followers.123':{'$exists': True}})
    
    0 讨论(0)
  • 2020-12-11 18:14

    Try the dot syntax:

    cursor = fols.find({'followers.123': {'$exists': True}})
    

    But also see my comment above. You can't have the same key more than once in a (sub-)document.

    0 讨论(0)
提交回复
热议问题