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?