T
T
TheInsable2016-12-23 13:54:56
MongoDB
TheInsable, 2016-12-23 13:54:56

How to properly update an array in mongodb?

I have a document like:

{
    _id: 1,
    comments: [
        {
            user: 1,
            comment: 'Hello!'
        },
        {
            user: 2,
            comment: 'Test'
        }
    ]
}

How can I update this document by adding another object to the comments array?
I also wanted to ask about findAndModify and Update, do I understand correctly that the main difference is that update does not return the modified document, or are there any other important differences between these two methods?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad_Fedorenko, 2016-12-23
@TheInsable

https://docs.mongodb.com/manual/reference/operator...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question