在 Mongo 中,有什么方法可以像原子操作一样进行检查和设置? [英] In Mongo any way to do check and setting like atomic operation?

查看:36
本文介绍了在 Mongo 中,有什么方法可以像原子操作一样进行检查和设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Mongo 中是否可以像原子操作一样进行检查和设置?我在预定酒店,如果有空房可以预定,但是如果两个或两个以上的人想同时预定怎么办.有没有类似于 Mongo 中的事务或任何方法来解决这个问题?

Is in Mongo any way to do check and setting like atomic operation ? I am making booking for hotels and if there is free room you can reserve, but what if two or more people want to reserve in same time. Is there anything similar to transaction in Mongo or any way to solve this problem ?

推荐答案

是的,这是 MongoDB findAndModify 命令.

Yes, that's the classic use case for MongoDB's findAndModify command.

专门用于 pymongo:find_and_modify.

Specifically for pymongo: find_and_modify.

这篇关于在 Mongo 中,有什么方法可以像原子操作一样进行检查和设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆