我正在尝试同时从我的收藏中扣除金额,因此我需要保持金额一致.
I am trying to deduct the amount from my collection concurrently so I need to maintain the amount consistent.
示例:
My balance -> 1000 User 1 -> trying to deduct 700 User 2 -> trying to deduct 800 (Both users are accessing same account using different device)他们试图同时借记金额.所以我需要并发
they try to debit the amount at the same time . So I need concurrency
在 mongoDB 中,我们可以使用 fsyncLock() 和 fsyncUnlock(),但我需要在 pymongo (Python) 模块中使用此功能.如何实现此功能?
In mongoDB we can use fsyncLock() and fsyncUnlock() but I need to use this feature in pymongo (Python) module. How can I achieve this feature?
推荐答案db.fsyncLock() 和 db.fsyncUnlock() 是 pymongo 不提供的 mongo shell 方法.相反,您可以调用 fsync 管理命令对 admin 数据库执行相同的操作.类似的东西:
db.fsyncLock() and db.fsyncUnlock() are mongo shell methods not available from pymongo. Instead, you can call to the fsync administrative command to perform the same operation against the admin database. Something like:
import pymongo db_host='__put_your_ip_or_hostname_here__' client = pymongo.MongoClient(db_host) db = client['admin'] dbmand("fsync", lock=True)但是,正如 kevinadi 在评论中所说,使用事务进行并发而不是 fsynclock.当数据和日志文件夹位于不同的卷/文件系统时,此命令用于执行文件系统级备份.
But, as kevinadi said in the comments, Use transactions for concurrency instead of fsynclock. This command is intended to be used to perform filesystem-level backups when the data and journal folders lives separate volumes/filesystems.
更多推荐
如何在pymongo中使用fsyncLock()和fsyncUnlock()锁定并发写操作
发布评论