How do I update a DocumentDb document?

I have a Category->Question relationship in my DocumentDb. The Category documents contain a string-reference to the Questions id. When I add a question, I want to update the list of strings referenced in a Category. This is my code:

    public async Task<string> CreateQuestion(Question question, string categoryId)
    {
        var res = await client.CreateDocumentAsync(collectionLink, question);
        var category = GetCategory(categoryId);
        if (category.Questions == null) {
            category.Questions = new List<string>();
        }
        category.Questions.Add(categoryId);
        await client.ReplaceDocumentAsync(category.SelfLink, category);
        return res.Resource.Id;
    }

Everything returns without error, but the category-document is not updated with the list of questions.

What am I missing?

Upvotes: 1

Views: 887

Answers (1)

I found an answer - sort of - in this old GitHub issue: https://github.com/Azure/azure-documentdb-dotnet/issues/7

I made my classes inherit from Resource instead of Document and now it works as expected.

Upvotes: 1

Related Questions