我如何将{allowDiskUse:true}放在pymongo上?

问题描述 投票:0回答:1

我有这个python代码:

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))

并且我收到此错误消息:pymongo.errors.OperationFailure:超出了$ group的内存限制,但不允许外部排序。传递allowDiskUse:true以选择加入。

如何使用allowDiskUse:true

mongodb pymongo
1个回答
2
投票
query = list(database.solution1.aggregate(pipe, allowDiskUse=True))
© www.soinside.com 2019 - 2024. All rights reserved.