【问题标题】:Pymongo ignoring allowDiskUse = TruePymongo 忽略 allowDiskUse = True
【发布时间】:2021-02-05 06:28:21
【问题描述】:

我查看了此问题的其他答案,但仍然无法正常工作。我正在尝试删除重复的案例,这里是功能:

def deleteDups(datab):
    col = db[datab]
    pipeline = [
    {'$group': {
        '_id': {
            'CASE NUMBER': '$CASE NUMBER',
            'JURISDICTION': '$JURISDICTION'},#needs to be case insensitive
            'count': {'$sum': 1},
            'ids': {'$push': '$_id'}
            }
        },
    {'$match': {'count': {'$gt': 1}}},
    ]
    results = col.aggregate(pipeline, allowDiskUse = True)
    count = 0
    for result in results:
        doc_count = 0
        print(result)
        it = iter(result['ids'])
        next(it)
        for id in it:
            deleted = col.delete_one({'_id': id})
            count += 1
            doc_count += 1
            #print("API call recieved:", deleted.acknowledged) debug, is the database recieving requests
            
    print("Total documents deleted:", count)

然而,每次,我都会得到这个回溯:

  File "C:\Users\*****\Documents\GitHub\*****\controller.py", line 202, in deleteDups
    results = col.aggregate(pipeline, allowDiskUse = True)
  File "C:\Python38\lib\site-packages\pymongo\collection.py", line 2375, in aggregate
    return self._aggregate(_CollectionAggregationCommand,
  File "C:\Python38\lib\site-packages\pymongo\collection.py", line 2297, in _aggregate
    return self.__database.client._retryable_read(
  File "C:\Python38\lib\site-packages\pymongo\mongo_client.py", line 1464, in _retryable_read
    return func(session, server, sock_info, slave_ok)
  File "C:\Python38\lib\site-packages\pymongo\aggregation.py", line 136, in get_cursor
    result = sock_info.command(
  File "C:\Python38\lib\site-packages\pymongo\pool.py", line 603, in command
    return command(self.sock, dbname, spec, slave_ok,
  File "C:\Python38\lib\site-packages\pymongo\network.py", line 165, in command
    helpers._check_command_response(
  File "C:\Python38\lib\site-packages\pymongo\helpers.py", line 159, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in.

我标出了一些保护隐私的路径。但是这条线让我非常抓狂:results = col.aggregate(pipeline, allowDiskUse = True) 非常明确地通过了 allowDiskUse = True,而 Mongo 只是忽略了它。如果我拼错了什么,我就瞎了。 True 必须大写才能在 python 中传递布尔值。

我觉得我在这里要疯了。

【问题讨论】:

  • 您在连接字符串中键入的用户的角色是什么?也许包括 dbPath?
  • 我是管理员。 db 变量是正确的,代码在较小的集合上运行良好。
  • 是的,但您还需要创建_tmp 文件夹的权限
  • 您复习了哪些问题?还可以链接到显示正确用法的驱动程序文档。

标签: python mongodb debugging pymongo


【解决方案1】:

根据documentation

Atlas 免费层和共享集群不支持聚合命令或其辅助方法的 allowDiskUse 选项。

(感谢Shane Harvey提供此信息)

【讨论】:

    猜你喜欢
    • 2020-08-14
    • 2016-10-24
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 2016-09-04
    • 2020-04-18
    • 1970-01-01
    • 2022-11-28
    相关资源
    最近更新 更多