且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以检查唯一性并在Cosmos DB存储过程中写文档吗

更新时间:2023-02-14 11:49:06

我可以确定即使创建了多个文档,该文档也只能创建一次客户正在尝试同时创建它?

Can I be sure that the document is only created once even if several clients are trying to create it at the same time?

Hein,关于您的关注,您可以深入研究文档,它说明了Cosmos DB中的ACID.

Hein, about your concern,you could dig into this document which expounds ACID in Cosmos DB.

在Azure Cosmos DB中,JavaScript运行时托管在数据库中引擎.因此,在存储过程中发出的请求以及触发器在与数据库会话相同的作用域内执行.这该功能使Azure Cosmos DB可以保证所有对象的ACID属性存储过程或触发器的一部分的操作.为了例子.

In Azure Cosmos DB, JavaScript runtime is hosted inside the database engine. Hence, requests made within the stored procedures and the triggers execute in the same scope as the database session. This feature enables Azure Cosmos DB to guarantee ACID properties for all operations that are part of a stored procedure or a trigger. For examples.

因此,我认为您的问题的答案是肯定的,因为原子性保证了事务中完成的所有操作都被视为一个单元,并且所有这些操作都已提交或全部都不提交.

So, i think the answer is yes for your question because the atomicity guarantees that all the operations done inside a transaction are treated as a single unit, and either all of them are committed or none of them are.

顺便说一句,您还可以在创建集合之前设置一个或多个唯一键,请参阅此

BTW,you also could set one or more unique keys before the creation of collection,please refer to this blog.