Mongodb mongo:更新$push失败,错误为;更新后生成的文档大于16777216“;

Mongodb mongo:更新$push失败,错误为;更新后生成的文档大于16777216“;,mongodb,push,insert-update,Mongodb,Push,Insert Update,我想使用update(..$push…)操作扩展一个大型数组 详情如下: 我有一个包含许多字段的大型集合“a”。在这些字段中,我想提取“F”字段的值,并将它们传输到一个大数组中,该数组存储在集合“B”中文档的一个字段中 我将过程分为几个步骤(以限制使用的内存) 下面是python程序: ... steps = 1000 # number of steps step = 10000 # each step will handle this number of documents start =

我想使用update(..$push…)操作扩展一个大型数组

详情如下:

我有一个包含许多字段的大型集合“a”。在这些字段中,我想提取“F”字段的值,并将它们传输到一个大数组中,该数组存储在集合“B”中文档的一个字段中

我将过程分为几个步骤(以限制使用的内存)

下面是python程序:

...
steps = 1000  # number of steps
step = 10000  # each step will handle this number of documents
start = 0

for j in range(steps):
    print('step:', j, 'start:', start)

    project = {'$project': {'_id':0, 'F':1} }
    skip = {'$skip': start}
    limit = {'$limit': step}
    cursor = A.aggregate( [ skip, limit, project ], allowDiskUse=True )

    a = []
    for i, o in enumerate(cursor):
        value = o['F']
        a.append(value)

    print('len:', len(a))
    B.update( {'_id': 1}, { '$push': {'v' : { '$each': a } } } )

    start += step
以下是该程序的输出:

step: 0 start: 0
step: 1 start: 100000
step: 2 start: 200000
step: 3 start: 300000
step: 4 start: 400000
step: 5 start: 500000
step: 6 start: 600000
step: 7 start: 700000
step: 8 start: 800000
step: 9 start: 900000
step: 10 start: 1000000
Traceback (most recent call last):
  File "u_psfFlux.py", line 109, in <module>
    lsst[k].update( {'_id': 1}, { '$push': {'v' : { '$each': a } } } )
  File "/home/ubuntu/.local/lib/python3.5/site-packages/pymongo/collection.py", line 2503, in update
    collation=collation)
  File "/home/ubuntu/.local/lib/python3.5/site-packages/pymongo/collection.py", line 754, in _update
    _check_write_command_response([(0, result)])
  File "/home/ubuntu/.local/lib/python3.5/site-packages/pymongo/helpers.py", line 315, in _check_write_command_response
    raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: Resulting document after update is larger than 16777216
步骤:0开始:0
步骤:1开始:100000
步骤:2开始:200000
步骤:3开始:300000
步骤:4开始:400000
步骤:5开始:500000
步骤:6开始:600000
步骤:7开始:700000
步骤:8开始:800000
步骤:9开始:900000
步骤:10开始:1000000
回溯(最近一次呼叫最后一次):
文件“u_psfFlux.py”,第109行,在
lsst[k].更新({''u id':1},{'$push':{'v':{'$each':a}})
文件“/home/ubuntu/.local/lib/python3.5/site packages/pymongo/collection.py”,第2503行,在更新中
排序规则=排序规则)
文件“/home/ubuntu/.local/lib/python3.5/site packages/pymongo/collection.py”,第754行,在更新中
_检查写入命令响应([(0,结果)])
文件“/home/ubuntu/.local/lib/python3.5/site packages/pymongo/helpers.py”,第315行,在check\u write\u command\u response中
raise WriteError(error.get(“errmsg”)、error.get(“code”)、error)
pymongo.errors.WriteError:更新后生成的文档大于16777216
显然,$push操作必须获取完整的数组!!!(我的预期是此操作将始终需要相同数量的内存,因为我们总是向数组追加相同数量的值)

简而言之,我不明白为什么update/$push操作失败并出现错误

或者。。。有没有办法避免这种不必要的缓冲

谢谢你的建议


Christian

我认为您的一个B文档接近16Mb(文档的mongodb默认限制),而
$push
使其通过限制我认为您的一个B文档接近16Mb(文档的mongodb默认限制),而
$push
使其通过限制