我有这样的数据:
_id:5a0f6c61d1154f2f9983ad74
name:"colla"
weight:"2"
status:"+"
time_exp:2017-11-18 00:37:31.946
_id:5a0f6c61d1154f2f9983ad74
name:"pepsi"
weight:"3"
status:"+"
time_exp:2017-11-18 00:37:31.946
_id:5a0f6c61d1154f2f9983ad74
name:"colla"
weight:"3"
status:"+"
time_exp:2017-11-18 00:37:31.946
由此我想找到所有带有"name": "colla", 'status': '+'
的非重复元素并等同于随机变量。
示例:从上面的数据获取所有"权重" (2,3)和等同。 (some_random1 = 2,some_random2 = 3)
我是怎么做的:
db.some_db.find_one({}, {"name": "cola","status":'+'}).sort(key=itemgetter('weight'), reverse=True)
,但我收到此错误:
'dict' object has no attribute 'sort'
求助于你