0

I have following document sample:

"_id" : ObjectId("5a569c3d093322018b514e31"),
"participants" : [
    {
        "user" : ObjectId("5a446a6169c8343283bdb1ad"),
        "unreadMessages" : [ ]
    },
    {
        "user" : ObjectId("5a4ff9bded4bae532bdd35f9"),
        "unreadMessages" : [ ]
    }
],
"created" : ISODate("2018-01-11T01:08:39.736Z")

I am given _id(5a569c3d093322018b514e31) and user id(5a446a6169c8343283bdb1ad).

How I can push a text string (test test) into the unreadMessages array of the first element in participants?

Julien Ambos
  • 2,010
  • 16
  • 29
eded
  • 3,778
  • 8
  • 28
  • 42
  • 1
    Try `db.collection.update( { _id:ObjectId("5a569c3d093322018b514e31"), "participants.user":ObjectId("5a446a6169c8343283bdb1ad") }, { "$push": { "participants.$.unreadMessages" : "test test"} } )` – s7vr Jan 11 '18 at 19:28
  • Possible duplicate of [Mongodb $push in nested array](https://stackoverflow.com/questions/27874469/mongodb-push-in-nested-array) – s7vr Jan 11 '18 at 19:29

0 Answers0