1

I have Document db and I have a scenario where I'm going to join two collections for required result, but I'm not able to join two collections.

This is the simple select query to get records:

SELECT 
c.DocumentName,
c.DocumentID,
c.VersionID,
c.VersionName,
c.PageID,
c.OCRSpan 
FROM c 
where ARRAY_CONTAINS([4780,4779], c.VersionID)
var endpoint = ConfigurationManager.AppSettings["DocDbEndpoint"];
var masterKey = ConfigurationManager.AppSettings["DocDbMasterKey"];

using (var client = new DocumentClient(new Uri(endpoint), masterKey))
{
    FeedOptions queryOption = new FeedOptions { MaxItemCount = 100 };
    int[] ids = { 4779 };

    //Execute Store Procedure                    
    var result = await client.ExecuteStoredProcedureAsync<string>("dbs/HOCRData/colls/HOCR/sprocs/getData/", new RequestOptions() { PartitionKey = new PartitionKey(Undefined.Value) }, ids);

    Console.WriteLine($" {result.Response} ");                    
    Console.ReadKey();
    ...

The code mentioned is only for a single collection, but I'm expecting to join two collections together.

Or is there any alternate way to join two collection documents?

1 Answer 1

4

You cannot join collections in Cosmos DB.

As for alternates, you have a few options that all require some significant changes:

  1. Put all your data into one collection. Then you can do joins.
  2. Keep your collections separate and do the join locally via code.
  3. Avoid joins all together by denormalizing your data to avoid the need to do joins.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.