Azure Cosmos db(Mongodb) transactional(Multi-document transactions cannot be run in a sharded collection)

(Neusoft)龍 挙兵(Ryuu.Kixyoheyi) 121 Reputation points
2021-09-09T06:36:48.927+00:00

when I add @Transactional on method, which add or update document
in method i call resp(extends MongoRepository) to add or update document
then error happen
There was an unexpected error (type=Internal Server Error, status=500).
Command failed with error 50841 (50841): 'Multi-document transactions cannot be run in a sharded collection' on server

I found that cosmos db's mongodb is 4.0
Is there has some way to using transactional in spring data connect cosmosdb(mongodb) ?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,501 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Oury Ba-MSFT 17,156 Reputation points Microsoft Employee
    2021-09-09T23:15:39.793+00:00

    Hi @Anonymous Thank you for posting your questions .
    Which command are you using? Azure Cosmos DB supports automatic, server-side sharding. It manages shard creation, placement, and balancing automatically. Azure Cosmos DB does not support manual sharding commands, which means you don't have to invoke commands such as addShard, balancerStart, moveChunk etc. You only need to specify the shard key while creating the containers or querying the data.

    Please see the supported cosmos DB's for MongoDB API Version 4.0
    https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/feature-support-40#transactions

    Regards,
    Oury