I have a List that looks something like:
[0] Student - GroupId: 1, Subject: "History"
[1] Student - GroupId: 1, Subject: "Math"
[2] Student - GroupId: 1, Subject: "Art"
[3] Student - GroupId: 2, Subject: "Spanish"
[4] Student - GroupId: 2, Subject: "Gym"
[5] Student - GroupId: 2, Subject: "English"
[6] Student - GroupId: 3, Subject: "Science"
[7] Student - GroupId: 3, Subject: "Science"
[8] Student - GroupId: 3, Subject: "Reading"
Where the structure of the class is like this:
public class Student
{
public int GroupId { get; set; }
public string Subject { get; set; }
}
With my Replace method, I am passing in a GroupId. For the passed in GroupId, I want to replace all Student instances with new Students.
Right now, my Replace is not doing anything. I inspected the Collections before my attempt to Replace and after, and the Lists are the same. I am not too familiar with MongoDriver, but it doesn't seem like there is a ReplaceMany? This is my attempt:
public static void ReplaceStudents(int GroupId, IMongoDatabase Database)
{
IMongoCollection<Node> collection = Database.GetCollection<Student>("Students");
List<Student> studentObjects= collection.Find(s => true).ToList();
List<Student> before = collection.Find(s => true).ToList();
var filter = Builders<Student>.Filter.Eq(n => n.GroupId, GroupId);
collection.ReplaceOneAsync(filter, new Student());
List<Student> after = collection.Find(s => true).ToList();
}
When calling the method:
ReplaceStudents(1, Database);