C# driver 2.0 Mongodb UpdateOneAsync

As you've already discovered, the C# code to use $addToSet is:

var filter = Builders<Student>.Filter.Eq(s => s.StudentId, studentId);
var update = Builders<Student>.Update.AddToSet(s => s.CoursesList, courseId);
var result = await collection.UpdateOneAsync(filter, update);

However, $addToSet is not going to work if the CourseList member has been stored in the collection as a null. The server requires that the existing value for $addToSet be an array (it can be an empty array).

The easiest solution is to just store an empty list for CoursesList instead of a null when there are no courses.