...

/

Update, Delete & Index Operations

Update, Delete & Index Operations

This lesson will teache you how to perform the update and delete user operations in C#. It will also teache you how to create indexes.

We'll cover the following...

In the previous lesson, we looked at how the basic CRUD operations, create and read, could be performed using C#. Let’s learn about some more of them below.

Update Users

Documents can be updated in a similar manner:

public async Task<bool> UpdateUser(ObjectId id, string udateFieldName, string updateFieldValue)
{
var filter = Builders<User>.Filter.Eq("_id", id);
var update = Builders<User>.Update.Set(udateFieldName, updateFieldValue);
var result = await _usersCollection.UpdateOneAsync(filter, update);
return result.ModifiedCount != 0;
}

In this example, function UpdateOneAsync is used, but if you want to change values of multiple documents, you can use UpdateMultipleAsync.

Synchronous siblings of these operations also ...