0

I have a Mongo DB table Notes with following structure

Id(autoincrement value)
UserId
Notes(Collection)

And now i need to add one more record into that existing Notes collection. How do i do it in Mongo DB using Mongo DB driver?

In my repository i tried something like following, but its not working

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

How do i insert a new record to existing collection in Mongo DB table?

1 Answer 1

1

Finally i got the answer which i was looking for. for achieving above i need to write something similar to this

studentsCol.UpdateOneAsync(
Builders<Student>.Filter.Eq(x => x.Id, studentId),
Builders<Student>.Update.Push(x => x.MarkList, newMark));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.