0

I'd like to know how to add or update one embedded document in mongodb? Thus how to add one answer item and how to update one answer item below? I'd also like to know how to do it using mongoose.

questions: [{
        "questionID": 1,
        "questionTitle": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur sed tortor. Integer",
        "questionText": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur sed tortor. Integer aliquam adipiscing lacus. Ut nec urna et arcu imperdiet ullamcorper. Duis at lacus. Quisque purus sapien,",
        "name": "Gabriel",
        "firebaseuser": "Nunc",
        "category": "Programming",
        "votesup": 516,
        "votesdown": 14,
        "beginningdate": "28/07/2020",
        "modifieddate": "24/08/2020",
        "enddate": "null",
        "questionclosed": false,
        "closereason": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur",
        "close_user": "sulkija",
        "answers": [{
            answerid:1,
            answertext: "1 XXXXXXXXXXXXXXXX CCCCCCCCCCCCCCCCCCCCCCCC DDDDDDDDDDDDDDDDDDDDDDDDDD ",
            answerer: "mika",
            firebaseanswerer: "hjjjjjjjjjjjjjjfas",
            answervotesup: 7,
            answervotesdown: 0,
            answerdate: "24/08/2020",
            answermodified: ""
            },
            {
                answerid:2,
                answertext: "Esimerkkivastaus 2 XXXXXXXXXXXXXXXX CCCCCCCCCCCCCCCCCCCCCCCC DDDDDDDDDDDDDDDDDDDDDDDDDD HHHHHHHHHHHHHHHHHHHHHHHHH",
                answerer: "mika",
                firebaseanswerer: "hjjjjjjjjjjjjjjfas",
                answervotesup: 7,
                answervotesdown: 0,
                answerdate: "30/08/2020",
                answermodified: ""
            }]
        },
}]
Hoppo
  • 1,130
  • 1
  • 13
  • 32
  • Please show us what you have tried so far so that we can help, otherwise you can find help with the documentationhere https://docs.mongodb.com/ and here https://mongoosejs.com/docs/documents.html – Hoppo Jun 11 '20 at 08:11
  • Take a look at https://stackoverflow.com/questions/10522347/mongodb-update-objects-in-a-documents-array-nested-updating and – Joe Jun 11 '20 at 08:28

0 Answers0