mongodb - Mongo:锁定单个文档以供 READ 和后续更新
问题描述
我有一个存储文档的 Mongo Collection。每个文档都有一个字段complexNestedObject,顾名思义,它包含一个复杂的嵌套对象。我必须创建一个实现以下逻辑的函数
updateComplexNestedObject(_id, data) {
1) read the document using _id as key
2) perform some logic based on input data and the content of the document
3) based on this logic determine the new value of complexNestedObject
4) update complexNestedObject with the new value
}
这个函数可以被不同的客户端同时调用,对于同一个文档_id但输入数据不同,所以我需要实现一些锁定机制。哪种锁定机制最好?我应该使用 Mongo 4 事务支持还是更好的一些应用解决方案?
解决方案
推荐阅读
- javascript - 模拟hover然后点击触发已经设置好的onclick功能
- c - 提高注册机 VM 上循环的简单自制 JIT 的性能
- reactjs - TypeError:无法读取 react.js 中未定义(读取“地图”)的属性
- c# - 无法让 Serilog 读取 appsettings.json 设置
- swiftui - 如何将 navigationTitle 与菜单按钮(toolbarItem)对齐?
- html - 移动设备的背景图片不居中
- windows - 具有 SSL 的 Apache 多站点配置 - httpd-vhosts.conf 、主机表和 .htaccess
- javascript - 如何在 googletag.cmd.push(function() { googletag.display('div-id'); }); 中捕获错误?
- javascript - TypeError [ERR_INVALID_ARG_TYPE] 为什么会这样
- python - “ImportError:无法导入 Django。您确定它已安装并在您的 PYTHONPATH 环境变量中可用吗?” 关于自制