【问题标题】:How do i put {allowDiskUse: true} on pymongo?我如何将 {allowDiskUse: true} 放在 pymongo 上?
【发布时间】:2020-08-14 02:38:46
【问题描述】:

我有这个 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: Exceeded memory limit for $group,但不允许外部排序。传递 allowDiskUse:true 以选择加入。

如何使用 allowDiskUse: true

【问题讨论】:

标签: mongodb pymongo


【解决方案1】:
query = list(database.solution1.aggregate(pipe, allowDiskUse=True))

参考:pymongo Collection level operations

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    • 2023-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多