我想用mongodb和python来处理一些数据,代码是这样的:
pipeline = [
{'$match':{'time':'03.02'}},
{'$group':{'_id':{'$slice':['$address',1]},'counts':{'$sum':1}}},
{'$sort':{'counts':-1}}
]
for i in item_info.aggregate(pipeline):
print i
但是有一些错误:
OperationFailure:命令SON([('汇总',u' item_info_3'),'管道',[{' $ match' :{' $和':[{' pub_date':{' $ lte':' 12.27',' $ gte& #39;:' 12.25'}},{' area':{' $ all':[' \ xe6 \ x9c \ x9d \ xe9 \ x98 \ xb3']}}]}},{' $ group':{'计算':{' $ sum':1},& #39; _id':{' $ slice':[' $ address',2,1]}}},{' $ limit':3在命名空间GanjiData上。)],(' cursor',{})])$ cmd failed:exception:invalid operator' $ slice'
我真的无法解决这个问题,mongodb版本是3.2.4