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:
Press + to interact
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
. ...
Access this course and 1400+ top-rated courses and projects.