Update

Partial document update.

When you need to update only part of the document, you can specify which properties should be updated. You can benefit from it in many ways: you don't need to prefetch all the data upfront, reduce the payload of a request, increment some property without replacing the entire document, ... If you want to replace the entire document, please refer to ReplaceOne action.

var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);

var person = new Person { Id = "record_id" Name = "Peter" };
var updateDefinition = Builders<Person>.Update.Set(x => x.Name , "Peter II");

await service.UpdateOneRequest(
    x => x.Id == person.Id,
    updateDefinition,
    new DatabaseUpdateOneOptions()
);

Check the information about entities on how your class objects are serialized.

Check the docs on how to form filters.

Last updated