【发布时间】:2023-02-17 06:32:30
【问题描述】:
我使用多个进程,它们并行运行以更新 MongoDb 集合中的日期。我使用这样的东西:
db.collection.bulkWrite(
[
{ updateOne : <document> },
{ updateOne : <document> },
{ updateOne : <document> },
{ updateOne : <document> },
],
{ ordered : false }
)
updateOne 查询经常更新同一个文档,但在文档不同的树中。我的查询看起来像这样:
{
'_id': 'ABC12345',
'idents.tree.subtreeId': $anyIdHere,
}
和更新集:
{ '$set': {
'idents.$.tree.entry': $newDictHere,
} }
如果两个进程现在对同一个文档执行bulkWrite(即ABC12345),但对于不同的subtreeIds,则第一个bulkWrite及其updateOnes不会保留在文档中。看起来存在并发问题,但我不知道是什么原因造成的。是否有任何我可能遗漏的 MongoDb 限制?我使用 pymongo 任何 Python 来执行 bulkWrite。
【问题讨论】:
-
您能否提供文档和更新的最小工作示例?
标签: mongodb concurrency pymongo