0
我試圖使用pymongo和蒙戈的聚合框架和這裏就是我在Python有:MongoDB的聚合框架錯誤
OperationFailure: command SON([('aggregate', 'call_log'), ('pipeline', [{'$match': {u'user': 1}}, {'$project': {'date': 1, 'status': 1, 'number': 1, 'description': 1}}, {'$group': {u'first_number': {u'$first': u'$number'}, '_id': SON([(u'number', u'$number')]), u'avg_number': {u'$avg': u'$number'}}}])]) failed: exception: can't convert from BSON type 2 to double
Python的代碼切:
#Process grouping
groups_list = []
if "fields" in group_json:
for k, v in group_json["fields"].items():
groups_list.append((k,'$' + k))
if len(groups_list) > 0:
obj_group_json.update({'_id': SON(groups_list)})
if "aggregate" in group_json:
for field in group_json["aggregate"]:
if field['func'] == "count":
obj_group_json.update({"count_" + field['name']: {'$sum': 1}})
else:
obj_group_json.update({field['func'] + "_" + field['name']:
{'$' + field['func']: '$' + field['name']}})
你有什麼想法,爲什麼?
你能包括你的python代碼嗎? –
我已更新該問題 – KennyPowers