> db.students3.insert([
... { "_id" : 1,
... "grades" : [
... { type: "quiz", questions: [ 10, 8, 5 ] },
... { type: "quiz", questions: [ 8, 9, 6 ] },
... { type: "hw", questions: [ 5, 4, 3 ] },
... { type: "exam", questions: [ 25, 10, 23, 0 ] },
... ]
... }
... ])
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 1,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})
>
>
>
> db.students3.update(
{},
{ $inc: { "grades.$[].questions.$[score]": 2 } },
{ arrayFilters: [ { "score": { $gte: 8 } } ], multi: true}
)
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 16837,
"errmsg" : "cannot use the part (grades of grades.$[].questions.$[score]) to traverse the element ({grades: [ { type: \"quiz\", questions: [ 10.0, 8.0, 5.0 ] }, { type: \"quiz\", questions: [ 8.0, 9.0, 6.0 ] }, { type: \"hw\", questions: [ 5.0, 4.0, 3.0 ] }, { type: \"exam\", questions: [ 25.0, 10.0, 23.0, 0.0 ] } ]})"
}
})
>