pymongo- How can I have distinct values for a field along with other query parameters

前端 未结 3 678
無奈伤痛
無奈伤痛 2021-02-03 20:01

I am using pymongo and want to have distinct values for a field such that I can also pass other query parameters. For example, I have entries like:

{
   id = \"m         


        
相关标签:
3条回答
  • 2021-02-03 20:19

    Actually there is a filter parameter you can pass in distinct method as mentioned in the pymongo Doc,

    Pymongo Distinct

    like this

    distinct_tags = db.mycoll.distinct("tags",{"category": "movie"})
    
    0 讨论(0)
  • 2021-02-03 20:32

    pymongo (since v1.1.1) supports collection.distinct('key')

    0 讨论(0)
  • 2021-02-03 20:33

    You have to make the distinct call on the cursor returned from a find instead of on the collection:

    tags = db.mycoll.find({"category": "movie"}).distinct("tags")
    
    0 讨论(0)
提交回复
热议问题