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.
Hamdy Ghanem commented
Don't believe this is just a limitation, there is no even a workaround to achieve this
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