将值插入Mongo DB中的现有集合



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

Id(autoincrement value)
UserId
Notes(Collection)

现在,我需要在现有的Notes集合中再添加一条记录。如何使用MongoDB驱动程序在MongoDB中实现这一点?

在我的存储库中,我尝试了以下内容,但它不起作用

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

如何在MongoDB表中的现有集合中插入新记录?

终于得到了我想要的答案。为了实现以上目标,我需要写类似于这个的东西

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

最新更新