title: [DocumentDB .NET SDK]What is the difference between ReadDocumentAsync and CreateDocumentQuery when replacing
body: <p>Please look at the code first.</p>
  
  <p>In step 8, the field is not updated.
  In step 11&amp;12, the field is updated.</p>
  
  <p>I have 2 questions.</p>
  
  <p>What is the difference between ReadDocumentAsync and CreateDocumentQuery when replacing?</p>
  
  <p>Is it appropriate to use the value obtained by DocumentQuery for replacement?</p>
  
  <hr>
  
  <p>ConsoleApp</p>
  
  <p>NuGet Package(Microsoft.Azure.DocumentDB 1.19.1,Newtonsoft.Json 9.0.1)</p>
  
  <hr>
  
  <pre><code>using Microsoft.Azure.Documents;
  using Microsoft.Azure.Documents.Client;
  using Microsoft.Azure.Documents.Linq;
  using Newtonsoft.Json;
  using System;
  using System.Collections.ObjectModel;
  using System.Configuration;
  using System.Linq;
  
  class Program
  {
      static string endpoint = ConfigurationManager.AppSettings["endpoint"];
      static string key = ConfigurationManager.AppSettings["key"];
      static string database = ConfigurationManager.AppSettings["database"];
      static string collection = ConfigurationManager.AppSettings["collection"];
      static void Main(string[] args)
      {
          ConnectionPolicy cp = new ConnectionPolicy()
          {
              ConnectionMode = ConnectionMode.Direct,
              ConnectionProtocol = Protocol.Https,
              RetryOptions = new RetryOptions()
              {
                  MaxRetryAttemptsOnThrottledRequests = 5,
                  MaxRetryWaitTimeInSeconds = 60,
              }
          };
  
          var client = new DocumentClient(new Uri(endpoint), key, cp);
          //Step1 Create Database
          client.CreateDatabaseIfNotExistsAsync(new Database { Id = database }).Wait();
  
          //Step2 Create Collection(400RU)
          client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(database),
              new DocumentCollection
              {
                  Id = collection,
                  PartitionKey = new PartitionKeyDefinition()
                  { Paths = new Collection&lt;string&gt;() { "/partitionKey" } }
              }
              , new RequestOptions { OfferThroughput = 400 }).Wait();
  
          //Step3 Insert TestData
          var id1 = Guid.NewGuid().ToString();
          client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(database, collection)
              , new TestDocument() { TestField = "initialvalue", PartitionKey = "default", Id = id1, }).Wait();
          var id2 = Guid.NewGuid().ToString();
          client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(database, collection)
              , new TestDocument() { TestField = "initialvalue", PartitionKey = "default", Id = id2, }).Wait();
  
          //Step4 ID1 GetDocument(ReadDocument)
          var readDocument = client.ReadDocumentAsync&lt;TestDocument&gt;(UriFactory.CreateDocumentUri(database, collection, id1),
              new RequestOptions() { PartitionKey = new PartitionKey("default") }).Result.Document;
  
          //Step5 ID2 GetDocument(DocumentQuery)
          var queryDocument = client.CreateDocumentQuery&lt;TestDocument&gt;(UriFactory.CreateDocumentCollectionUri(database, collection),
              new FeedOptions { MaxItemCount = 1, EnableCrossPartitionQuery = false, })
              .Where(x =&gt; x.PartitionKey == "default" &amp;&amp; x.Id == id2)
              .AsDocumentQuery().ExecuteNextAsync&lt;TestDocument&gt;().Result.FirstOrDefault();
  
          //Step6 ChangeValue
          readDocument.TestField = "newvalue";
          queryDocument.TestField = "newvalue";
  
          //Step7 ID1 Replace
          var updateResult1 = client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(database, collection, readDocument.Id), readDocument).Result;
          //Step8 ID2 Replace
          var updateResult2 = client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(database, collection, queryDocument.Id), queryDocument).Result;
  
          //Step9 ID1 select
          var id1Updated = client.ReadDocumentAsync&lt;TestDocument&gt;(UriFactory.CreateDocumentUri(database, collection, id1),
              new RequestOptions() { PartitionKey = new PartitionKey("default") }).Result.Document;
          //Step10 ID2 select
          var id2Updated = client.ReadDocumentAsync&lt;TestDocument&gt;(UriFactory.CreateDocumentUri(database, collection, id2),
              new RequestOptions() { PartitionKey = new PartitionKey("default") }).Result.Document;
  
          Console.WriteLine(id1Updated.TestField); //newvalue
          Console.WriteLine(id2Updated.TestField); //initialvalue
          Console.ReadLine();
  
          //Step11 ID2 SetPropertyValue
          queryDocument.SetPropertyValue("testField", "newvalue2");
          //Step12 ID2 Replace
          var updateResultX = client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(database, collection, queryDocument.Id), queryDocument).Result;
          //Step13 ID2 select
          var id2UpdatedX = client.ReadDocumentAsync&lt;TestDocument&gt;(UriFactory.CreateDocumentUri(database, collection, id2),
              new RequestOptions() { PartitionKey = new PartitionKey("default") }).Result.Document;
          Console.WriteLine(id2UpdatedX.TestField); //newvalue2
          Console.ReadLine();
      }
  }
  public class TestDocument : Document
  {
      [JsonProperty("partitionKey")]
      public string PartitionKey { get; set; }
      [JsonProperty("testField")]
      public string TestField { get; set; }
  }
  </code></pre>