0

I have a below collection in my mongoDB.

{
    "_id" : "5a0d994082909617400f101a",
    "Qusage" : [
    {
          "_id" : "5a0d994082909617400f501",
          "code" : "A",
          "QUESTION_SET" : {
                "ID" : "5a2dfbade11cd52d77039098",
                "TEMPLATENAME" : "AAA",
                "NAME" : "CCC",
                "QUESTION_SECTION" : [{
                    "A":"1"
                }]
            }

    },
    {
          "_id" : "5a0d994082909617400502",
          "code" : "A",
          "QUESTION_SET" : {
                "ID" : "5a2dfbade11cd52d77039095",
                "TEMPLATENAME" : "AAA",
                "NAME" : "CCC",
                "QUESTION_SECTION" : [{
                    "A":"1"
                }]
            }

    }]
}

How to update the all values under "QUESTION_SET"?

Hexfire
  • 5,945
  • 8
  • 32
  • 42
Varun
  • 85
  • 1
  • 7
  • 1
    Possible duplicate of [MongoDB - Update objects in a document's array (nested updating)](https://stackoverflow.com/questions/10522347/mongodb-update-objects-in-a-documents-array-nested-updating) – Murat Gündeş Dec 19 '17 at 06:32
  • Can we able to use "_id" : ObjectId("4faaba123412d654fe83hg876") instead of user_id from the above example. Because i am getting exception like this "Cannot apply $addToSet to a non-array field. Field named 'QUsage' has a non-array type Object in the document _id: ObjectId('5a317011e11cd52d770390f6')'" – Varun Dec 19 '17 at 08:21
  • Can you update the question to include the query that you have tried from the linked example ? What is your mongo server version ? Update specific fields in QUESTION_SET ? or add new fields to the QUESTION_SET ? – s7vr Dec 19 '17 at 14:05

0 Answers0