update cosmos db document with new values c#

class Program
{
static void Main(string[] args)
{
NewMethod().Wait();

}

private static async Task NewMethod()
{
try
{
var client = new DocumentClient(new Uri(“uri”), “key”);

//Fetch the Document to be updated
var doc = client.CreateDocumentQuery<RootObject>(UriFactory.CreateDocumentCollectionUri(“Db-dev”, “collection”))
.Where(t => t.id == “id”).AsEnumerable()
.FirstOrDefault();

List<string> ok = new List<string>() { “d1”, “d2” };
doc.DevicesList.AddRange(ok);

//update document

var result = client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(“Db-dev”, “collection”, “id”), doc).Result.Resource;

}

catch (Exception ex)
{

throw;
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s