如何在使用多个集合的DocumentDB中使用存储过程 [英] How can I use stored procedures in DocumentDB that use multiple collections

查看:45
本文介绍了如何在使用多个集合的DocumentDB中使用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在使用C#在DocumentDB实例上运行操作,并且真的很喜欢它.我有很多C#代码,它们从多个集合中查询以根据前两个集合之间的关系创建新的集合.

I have been using C# to run operations on a DocumentDB instance and really like it so far. I have a lot of C# code that queries from multiple collections to create new collections from the relationships between the first two collections.

从本质上来说,我可以将我的逻辑上移到存储过程中的服务器上吗?我尝试自己回答这个问题,但是我所能找到的只是有关如何获取与存储过程关联的集合的文档.所以我想,我可以调用第一个集合时调用另一个存储过程的存储过程吗?

Can I essentially move my logic up to the server in stored procedures? I tried answering this question for myself, but all I could find was documentation on how to acquire the collection associated with the stored procedure. So then I thought, could I call a stored procedure that called another stored procedure, passing in the first collection?

有什么办法可以以某种方式引用存储过程中的多个集合吗?

Is there any way I can refer to multiple collections in a stored procedure somehow?

如果将所有内容都存储在同一个集合中,找到一种更容易的方法来了解每个集合"的内容会更容易吗?

Would it be easier to find an easier way to know what belongs to each "collection" if I store everything in the same collection?

推荐答案

存储过程在单个集合(或分区集合中的单个分区)中运行.调用存储过程只能对该集合/分区中的数据进行操作.

Stored procedures run inside of a single collection (or a single partition in a partitioned collection). A call to a stored procedure can only operate on the data in that collection/partition.

当我看到这个问题时,我通常想知道您是在考虑将集合作为SQL世界中表的直接类比,还是甚至使用MongoDB世界中的集合"一词.在DocumentDB中,最好不要按类型将数据分开,而应在同一集合中混合不同类型的数据,并沿其他横向扩展边界(如租户,用户,地理位置等)进行分离.存储过程不需要跨越租户,用户或地理位置边界,它就能为您提供完全ACID跨文档交易.

When I see this question asked, I usually wonder if you are thinking of collections as a direct analog to tables from the SQL world or even the use of the word "collection" from the MongoDB world. In DocumentDB it's best to not separate your data up by type but rather to mix data of different types in the same collection and separate along some other scale out boundary like tenant, user, geography, etc. If you do that, as long as your stored procedure doesn't need to cross that tenant, user, or geography boundary, it'll be able to provide you with fully ACID cross-document transactions.

这篇关于如何在使用多个集合的DocumentDB中使用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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