I am creating a .Net Console application to read information in DocumentDB. The console application has data coming from EventHub and inserts / updates the latest data when it gets to the cloud.
I am trying to read a unique document from DocumentDB, and I can confirm that the document exists before the document is requested.
if (DocumentDBRepository<DocumentDBItem>.DoesItemExist(name)) { device = await DocumentDBRepository<DocumentDBItem>.GetItemAsync(name); }
I used this Microsoft tutorial on creating a repository to access DocumentDB records and have successfully used almost all of the methods. I can update / delete / query the database, but I cannot read the particular item.
First, he threw an exception requesting PartitionKey. Therefore, I modified the method to add the PartitionKey used by the database to the query. As soon as I added PartitionKey, it throws another exception with the message "Resource not found"
public static async Task<T> GetItemAsync(string id) { try { RequestOptions options = new RequestOptions(); options.PartitionKey = new PartitionKey("DeviceId"); Document document = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id), options); return (T)(dynamic)document; } catch (DocumentClientException e) { if (e.StatusCode == HttpStatusCode.NotFound) { return null; } else { throw; } } }

I already changed my calls to use "GetItemsAsyc" and get IEnumerable of Documents and get the first item in the list, but it doesn't make sense why I can use all the other methods from the tutorial, but it continues to throw exceptions saying: "The resource is not found. "
Exception I get:
"Message: {\"Errors\":[\"Resource Not Found\"]}\r\nActivityId: e317ae66-6500-476c-b70e-c986c4cbf1d9, Request URI: /apps/e842e452-2347-4a8e-8588-2f5f8b4803ad/services/2c490552-a24d-4a9d-a786-992c07356545/partitions/0281cfdd-0c60-499f-be4a-289723a7dbf9/replicas/131336364114731886s"
source share