Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
CRUD

Update Data - .NET SDK

Updates are the same as creating a new document. When updating documents, all writes must happen in a transaction.

El siguiente ejemplo muestra cómo modificar un objeto existente. En este ejemplo, actualizamos el Name y Age propiedades de un objeto Dog:

var dog = realm.All<Dog>().First();
realm.WriteAsync(() =>
{
dog.Name = "Wolfie";
dog.Age += 1;
});

Una inserción te permite crear o modificar un documento sin saber si el documento ya existe. Para obtener más información, consulta Actualizar un objeto Realm.

The following code demonstrates how to update a collection.

realm.Write(() =>
{
// Create someone to take care of some dogs.
var ali = new Person { Id = id, Name = "Ali" };
realm.Add(ali);
// Find dogs younger than 2.
var puppies = realm.All<Dog>().Where(dog => dog.Age < 2);
// Loop through one by one to update.
foreach (var puppy in puppies)
{
// Add Ali to the list of Owners for each puppy
puppy.Owners.Add(ali);
}
});

Nota

Because realm uses implicit inverse relationships between the Dog's Owners property and the Person's Dogs property, Realm automatically updates Ali's list of dogs at the same time we update each dog's Owners list.

Volver

Filtrar y ordenar

En esta página