开发者社区 问答 正文

关于mongodb的aggregate()中$slice的使用

mongodb中使用aggregate(函数作聚合),pipe是这样写的:

pipe = [
    {'$match':{'time':'03.02'}},
    {'$group':{'_id':{'$slice':['$address',0,1]},'counts':{'$sum':1}}},
    {'$sort':{'counts':-1}}
]

address字段是list型,然后想取出address中第一项,出现一个就加一,但是总是报错:

OperationFailure: command SON([('aggregate', u'item_info_3'), ('pipeline', [{'$match': {'time': '03.02'}}, {'$group': {'counts': {'$sum': 1}, '_id': {'$slice': ['$address', 0, 1]}}}, {'$sort': {'counts': -1}}]), ('cursor', {})]) on namespace GanjiData.$cmd failed: exception: invalid operator '$slice'

不知道是为什么?

展开
收起
蛮大人123 2016-06-15 13:40:58 4633 分享 版权
1 条回答
写回答
取消 提交回答