我无法按价格排序数据。
我试过了,但结果并不像我预期的那样。
代码测试:
from pymongo import MongoClient
client = MongoClient().ecome
col = client['post_product']
data = []
GetData = col.find({'Category':'Handphone'}).sort([('Price', pymongo.ASCENDING)]).limit(10)
for x in GetData:
listed = dict(
title=x['Title'],
price=x['Price']
)
data.append(listed)
print data
结果是:
[{
'price': '10',
'title': 'tresemse'
}, {
'price': '200',
'title': 'muaral winner'
}, {
'price': '30',
'title': 'troboca'
}, {
'price': '400',
'title': 'brek yule'
}, {
'price': '50',
'title': 'moun yus'
}]
[{
'price': '10',
'title': 'tresemse'
}, {
'price': '30',
'title': 'troboca'
}, {
'price': '50',
'title': 'moun yus'
}, {
'price': '200',
'title': 'muaral winner'
}, {
'price': '400',
'title': 'brek yule'
}]