Support multiple collections in stored procedures
Currently CosmosDB Stored procedures only allow access to a SINGLE collection (because they seem to be scoped to collections rather than to the database), via getContext() :
var collection = getContext().getCollection();
But any "useful" / "real-life" application using ComosDB will typically have to interact with more than one collection. For example, it is currently IMPOSSIBLE to insert documents into two distinct collections within a database using a single stored procedure -- a VERY SERIOUS drawback / limitation.
I would propose that stored procedures be scoped to the database level and then we would be allowed to do something like:
var widgets_collection = getContext().getCollection( "widgets" );
var gadgets_collection = getContext().getCollection( "gadgets" );
A single stored procedure would have access to any collection within the database. Also, operations on documents within multiple collections would be a single atomic transaction.
This is currently not on our roadmap but will revisit this in future planning cycles.
Thank you for your suggestion.
Folks, it's not a limitation, it's a distributed storage, design your data model properly with eventual consistency in mind. Use Change Feed and trigger cascade changes with Azure Functions.
Hamdy Ghanem commented
Don't believe this is just a limitation, there is no even a workaround to achieve this
The link is dead...
I just noticed this limitation, and it SUCKS. As mentioned in the description, how can anyone take CosmosDB seriously if we can't even update multiple collections in a single transaction? And this is NOT on your roadmap. Very disappointed indeed.
I am using cosmo db for my application. How can I query data from multiple collections, perform operations on it and then save it in another collection. If stored procedures are at collection level, what is the work around to do this type of stuff. Should I switch to other NoSql databases like MongoDB or Cassandra
Alexander Arvei Yngling commented
Google AppEngine Datastore supports cross-entity-group transactions for up to 25 entity groups (cf. https://cloud.google.com/appengine/docs/standard/java/datastore/transactions ), and is a feature I have used heavily, but never with more than 5 groups, and usually only 2.
Being able to do a cross-partition transaction with only 2 partitions would be extremely useful for me, 5 would be even better.
Takekazu Omi commented
I want a transaction of the document that has been saved in multiple collections.
Such as global transaction.
It does not matter even if there is a limit to the consistency of this model.