简体   繁体   中英

Mongodb query using python

I have key-value pairs stored in MongoDB collections in the following format.

collection 1:
{ entertainment, 22
  popcorn,14
}

collection 2:
{ entertainment, 11
  movie, 16
}

How do i query from python to MongoDB in such a way to find the collection with the highest value/frequency of a key ("entertainment" in this case) ?

Expected output: collection 1

在mongo shell上,我将按照以下方式进行操作,使用pymongo驱动程序可以很容易地复制它。

db.getCollection('mydummycoll').aggregate([{$sort:{valueToSort:-1}},{$limit:1}])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM