0

I have this python code:

import pymongo
import time
start_time = time.time()

connection_string = 'mongodb://localhost'
connection = pymongo.MongoClient(connection_string)
database = connection.solutions

pipe = [ 
  {
    '$project':{
      "_id":0
    }
  },
  {
    '$group':{
      "_id":{
        "vehicleid":"$vehicleid",
        "date":"$metrictimestamp"
      },'count':{'$sum':1}
    }
  }
         ]
query = list(database.solution1.aggregate(pipe))
print("--- %s seconds ---" % (time.time() - start_time))

And I'm getting this error message: pymongo.errors.OperationFailure: Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in.

How can I use the allowDiskUse: true?

JediJesus
  • 329
  • 1
  • 9
  • Does this answer your question? [Can't get allowDiskUse:True to work with pymongo](https://stackoverflow.com/questions/27272699/cant-get-allowdiskusetrue-to-work-with-pymongo) – whoami - fakeFaceTrueSoul Apr 29 '20 at 21:02

1 Answers1

2
query = list(database.solution1.aggregate(pipe, allowDiskUse=True))

Ref: pymongo Collection level operations

Belly Buster
  • 8,224
  • 2
  • 7
  • 20