0
{
    "_id": {
        "$oid": "5bd8fa85bfbf4e27d86c73eb"
    },
    "status": {
        "iat": 1540947201356,
        "exp": 1540950801358
    },
    "code": "1cmTwKC7",
    "mongoDate": {
        "$date": "2018-10-31T00:41:56.016Z"
    },
    "form": [
        {
            "type": "tf",
            "text": "The first form ever. Welcome...",
            "opts": [],
            "responses": []
        }
    ],
    "updateDate": "October 30th, 2018, 8:47 PM",
    "date": "2019",
    "notes": "notes for this lecture.",
    "name": "TEST",
    "user": {
        "$oid": "5bcfd8a8da59d54024172d5c"
    },
    "course": {
        "$oid": "5bd8fa6cbfbf4e27d86c73ea"
    },
    "__v": 1
}

I have a document which is of the form above. I wanted to push a value into the responses array of a document which is in the form array. Im not sure how to do this using mongoose for MongoDB, and havent been able to find a direct answer. Thanks in advance.

Kai Ferrall
  • 81
  • 2
  • 12
  • Still, the question is incomplete as it seems you need to have some condition so you can choose, on which `form[index]` you need to update the response. – Suman Kundu Oct 31 '18 at 02:11
  • @SumanKundu yeah I tried just query for the document I want and then pushing directly by: document.form[index].responses.push(item) but then when I do document.save() it isnt saving in the database. – Kai Ferrall Oct 31 '18 at 02:37

0 Answers0