Skip to content Skip to sidebar Skip to footer

MongoDB Doesn't Handle Aggregation With AllowDiskUsage:True

the data structure is like: way: { _id:'9762264' node: ['253333910', '3304026514'] } and I'm trying to count the frequency of nodes' appearance in ways. Here is my code us

Solution 1:

How should I solve this problem and get the answer I want?

This is because in PyMongo v3.6 the method signature for collection.aggregate() has been changed. An optional parameter for session has been added. The method signature now is :

aggregate(pipeline, session=None, **kwargs)

Applying this to your code example, you can specify allowDiskUse as below:

node = db.way.aggregate(pipeline=[
                {'$unwind': '$node'},
                {'$group': {
                          '_id': '$node',
                          'appear_count': {'$sum': 1}
                          }
                 },
                 {'$sort': {'appear_count': -1}},
                 {'$limit': 10}
               ],
               allowDiskUse=True
        )

See also pymongo.client_session if you would like to know more about session.


Solution 2:

js is case sensitive, please use lowercase boolean true

 {'allowDiskUse': true}

Post a Comment for "MongoDB Doesn't Handle Aggregation With AllowDiskUsage:True"