0

I'm trying to insert a new document to a cosmos database running locally with SQLAPI in the Cosmos Emulator. Selecting documents works fine but when I try to insert with below code I get the following error:

Response status code does not indicate success: NotFound (404); Substatus: 1003; ActivityId: 10e20d81-559a-47b3-8eef-021ce4138279; Reason: (Message: {"Errors":["Owner resource does not exist"]}

Code:

async Task<Product> IProductRepository.Add(Product product)
        {
            var container = cosmosClient.GetContainer("Invertory", "Products");
            product.Id = Guid.NewGuid().ToString();
            product.Category = new Category() { Name = "test" };
            var x = await container.UpsertItemAsync<Product>(product);
            return product;
        }

It seems that the recourse (database) I try to reach not exists, but when I do a query with the same database and container and with the following code I get the expected results.

async Task<Product> IProductRepository.Get(string Id)
        {            
            var container = cosmosClient.GetContainer("Inventory", "Products");
            var iterator = (from p in container.GetItemLinqQueryable<Product>()
                            where p.Id.Equals(Id)
                            select p).ToFeedIterator();

            return iterator.HasMoreResults ? (await iterator.ReadNextAsync()).First() : null;
        }

What am I missing here?

4
  • 5
    Seems to be a typo in function "IProductRepository.Add". Invertory should be Inventory Commented Sep 22, 2020 at 9:03
  • 2
    OMG, I'm looking at this for hours, and missed it. Thanks! Commented Sep 22, 2020 at 9:18
  • @gkulshrestha Can you post your answer ? Commented Sep 23, 2020 at 1:34
  • @Jason posted my answer. Just thought there wasn't much to the answer so didn't post :) Commented Sep 23, 2020 at 2:24

1 Answer 1

4

There is a typo in function "IProductRepository.Add". Invertory should be Inventory.

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.