将值插入 Mongo 数据库中的现有集合

Insert value to existing collection in Mongo DB

我有一个 Mongo DB table Notes 具有以下结构

Id(autoincrement value)
UserId
Notes(Collection)

现在我需要在现有的 Notes 集合中再添加一条记录。我如何使用 Mongo 数据库驱动程序在 Mongo 数据库中执行此操作?

在我的存储库中,我尝试了如下操作,但它不起作用

public NoteUser AddNote(string userId, Note note)
{
    var filters = Builders<NoteUser>.Filter.Eq(x=>x.UserId, userId);
    context.Notes.InsertOne(filter,note);
}

如何向 Mongo 数据库 table 中的现有集合插入新记录?

终于得到了我一直在寻找的答案。为了实现上述目标,我需要写 类似于此

studentsCol.UpdateOneAsync(
Builders<Student>.Filter.Eq(x => x.Id, studentId),
Builders<Student>.Update.Push(x => x.MarkList, newMark));