如果下面有一个时间序列方案,如何在“信息”字段中按时间序列键名(例如20180705)排序并获取所有值 db.MyCollection.find({“ A”:“ JOHN”})。sort(.....)
{
"Name": "JOHN",
"ID": ...,
"Info":{
"20180705":{"Value":"100"},
"20180704":{"Value":"90"},
"20180703":{"Value":"150"},
"20180702":{"Value":"70"},
}
}
答案 0 :(得分:0)
您可以使用收藏集模块:
import collections
dict = {"Info":{
"20180705":{"Value":"100"},
"20180704":{"Value":"90"},
"20180703":{"Value":"150"},
"20180702":{"Value":"70"},
}
}
collections.OrderedDict(sorted(dict["Info"].items()))