3
votes

Hi We are facing issue while querying . The document exists in the database.

"Message: {\"Errors\":[\"Resource Not Found\"]}\r\nActivityId: 03866338-6596-49b6-8704-1726cb373bfb, Request URI: /apps/ab277caf-ee90-4cc3-96cb-4d4ec5ae2b13/services/17e48284-a3a0-40c5-b5ec-40bd3f207472/partitions/27cb7777-5add-4f72-8a73-1fc8fe34e7bf/replicas/131603393672093060p/, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.19.162.2"

Document in Database

{
    "consumername": "testconsumer",
    "tablename": "Table1",
    "securityaccount": "v-naagga",
    "logtime": "2018-01-13T21:42:21.3040338-08:00",
    "securitydefinition": {
        "tablename": "table1",
        "ColumnList": {
            "columnname": "name",
            "columndatatype": "string"
        },
        "RowSecurity": {
            "columnname": "address",
            "operator": "operator",
            "condition": "somecondition"
        }
    },
    "id": "15554839-096d-4072-8f38-af2e9c64b452",
    "_rid": "LmUiAONSDQQBAAAAAAAAAA==",
    "_self": "dbs/LmUiAA==/colls/LmUiAONSDQQ=/docs/LmUiAONSDQQBAAAAAAAAAA==/",
    "_etag": "\"00002e04-0000-0000-0000-5a5aedd60000\"",
    "_attachments": "attachments/",
    "_ts": 1515908566
}

Below is the update method code which is throwing this Error

{
            try
            {
                RequestOptions options = new RequestOptions();
                options.PartitionKey = new PartitionKey(id);
                options.ConsistencyLevel = ConsistencyLevel.Session;
                return await client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, SecurityCollectionId, id), item,options).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.Log(ErrorLevel.Error, ex.Message);
                throw ex;
            }
        }
1
Hi, any updates now? Does my answer helps you?Jay Gong
Hi Jay Thanks for checking i checked in my code i m passing correct values for parition. So issue still exists ...Naveen Aggarwal
Hi,Naveen. Please see my update answer. The code works well for me. If any concern, please let me know.Jay Gong

1 Answers

6
votes

According to my observations, I think your issue should be partition key settings error.

Please refer to this official document.You need to provide the value of the partition key, not the name of the field which stores the partition key.

For example , my container is created like this:

enter image description here

The partition key is "name" for my collection here. You could check your collection's partition key.

And my documents as below :

{
    "id": "1",
    "name": "jay"
}

{
    "id": "2",
    "name": "jay2"
}

My partitionkey is 'name', so here I have two paritions : 'jay' and 'jay1'.

So, here you should set the partitionkey property to 'jay' or 'jay2',not 'name'.

try
   {
     RequestOptions options = new RequestOptions();
     options.PartitionKey = new PartitionKey("jay");
     options.ConsistencyLevel = ConsistencyLevel.Session;
     return await client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, SecurityCollectionId, id), item,options).ConfigureAwait(false);
   }
     catch (Exception ex)
   {
     Logger.Log(ErrorLevel.Error, ex.Message);
     throw ex;
   }

Hope it helps you.


Update Answer :

I created a sample document as same as yours and replaced it successfully. enter image description here

Please refer to my test code.

using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using System;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {

        private static DocumentClient client;

        static string endpoint = "***";
        static string key = "***";
        static string database = "***";
        static string collection = "***";
        static void Main(string[] args)
        {

            client = new DocumentClient(new Uri(endpoint), key);

            try
            {
                Sample querysample = client.CreateDocumentQuery<Sample>(
                UriFactory.CreateDocumentCollectionUri(database, collection))
                .Where(so => so.id == "1")
                .AsEnumerable()
                .First();

                Console.WriteLine(querysample.tablename);

                querysample.tablename = "Table2";

                RequestOptions options = new RequestOptions();
                options.PartitionKey = new PartitionKey("1");
                options.ConsistencyLevel = ConsistencyLevel.Session;
                var result =  client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(database, collection, "1"), querysample, options).Result;
            }
            catch (Exception ex)
            {
                throw ex;
            }


            Console.ReadLine();
        }
    }

    public class Sample
    {
        public string id { get; set; }
        public string tablename { get; set; }
    }
}

id is my partition key and the value is '1'. Would you please check the differences between our codes?

If any concern , please let me know.