私はpymongoとmongoの集約フレームワークを使用しようとしています.Pythonから得たものは次のとおりです:
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']}})
理由はありますか?