关于mongodb的aggregate()中$slice的使用
PHP中文网
PHP中文网 2017-05-02 09:18:00
0
1
750

在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'

不知道是为什么,请高手看看,不胜感激!

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
大家讲道理

I didn’t know you mongodb的版本是多少,据mongodb docs上显示,aggregation$slice是在mongodb 3.2 joined later.

See
https://docs.mongodb.org/manual/reference/operator/aggregation/slice/

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template