1

I'm trying to use pymongo and mongo's aggregation framework and here's what I got from 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's code cut:

    #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']}})

Do you have any ideas why?

1
  • could you include your python code? Commented May 30, 2012 at 15:59

1 Answer 1

1

BSON type 2 is a string, so it seems to throw an error converting it to an integer.

Can you output: obj_group_json? Also, check your data - do you have any number data that isnt a number?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.