0
  "date_added": {
    "$date": "2018-02-27T21:34:31.144Z"
},
"malls": [
    {
        "name": "DFM",
        "geocoordinates": "-6.7726935,39.2196418",
        "region": "Kentucky",
        "show_times": [],
        "_id": {
            "$oid": "5a95d3ed053cc1444eadaeae"
        }
    },
    {
        "name": "MkHouse",
        "geocoordinates": "-6.8295944,39.2738459",
        "region": "Kenon",
        "show_times": [],
        "_id": {
            "$oid": "5a95d429053cc1444eadaeaf"
        }
    }
],
"title": "Black Panther",

I need to find/query malls with name == "DFM" and push data to show_times array, can anybody help! Which is the best way to handle this. I already query using _id and it worked and have this document. Now how can i push show_times? I'm using mongoose v5.5.1

Ally Makongo
  • 269
  • 5
  • 14

1 Answers1

1

Try this, It basically inserts the showtime where it found name field in malls array equal to DFM, $ operator is used for this

model.update(
       { _id: "givenObjectId",
         "malls.name" : "DFM"
       },
       {
          $push : {"malls.$.show_times" : data }
       }
    )

More details on the $ operator

Parth Acharya
  • 545
  • 3
  • 13