microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
94 stars 64 forks source link

Are multiple types within one container supported? #563

Open KnyGoo opened 3 years ago

KnyGoo commented 3 years ago

Hi,

Is there support for multiple object types within one container? If there is, how to handle transaction management for this? After reading CosmosDB documentation, this approach is recommended when objects share the same partition key. I want to do this because I need to persist multiple objects within one transaction and following CosmosDB documentation they need to be in the same logical partition therefore:

"Only documents from the same logical partition can participate in a single transaction. Consequently, writes to different containers can’t be a part of the same transaction."

Example of one container from Cosmos DB documentation: ` { "id": "", "type": "post", "postId": "", "userId": "", "title": "", "content": "", "creationDate": "" }

{ "id": "", "type": "comment", "postId": "", "userId": "", "content": "", "creationDate": "" }

{ "id": "", "type": "like", "postId": "", "userId": "", "creationDate": "" } ` Is it possible to have a Post, Comments and Like repository? Can I set the type anywhere?

Personal example: I have documents en batches. A batch can have a lot of documents (1-N). When I receive a document I would like to create the document and upsert the batch. The reason I would like to upsert the batch is to avoid complex queries afterwards and to work event driven (once I have all documents I will start processing the batch).

With kind regards,

Kenny