Mongodb Third-level Nested Array Modification Problem

  mongodb, question

The current data structure is like this

course:{
 name:String,
 chapter: [{
 name: String,
 knowledge: [{
 name: String,
 exam: [{
 name: String,
 }]
 }]
 }]
 }

If you want to modify knowledge.name, how do you write the modification statement? This is what I wrote before when I modified chapter.name

Course.update({
 "chapter._id": req.body.id
 }, {
 $set: {
 "chapter.$.name": name, // name
 }
 })
 .exec(function(err, num) {
 
 
 });

I don’t know how to use the $ locator when modifying the third-level nested document.

Actually, I think it’s complicated. Nested queries and nested modifications are not very efficient if I look for nodes layer by layer.
Document database, to put it bluntly, is not much nested and is always a string of json-like strings.
The fastest and most direct way is as follows:

jsondb.term.update({"_id" : ObjectId("54c1a899eb21ac9c995d3eb2")}, {$set:{
 "_id" : ObjectId("54c1a899eb21ac9c995d3eb2"),
 "course" : {
 "name" : "String",
 "chapter" : [
 {
 "name" : "String",
 "knowledge" : [
 {
 "name": "So it is",
 "exam" : [
 {
 "name" : "String"
 }
 ]
 }
 ]
 }
 ]
 }
 }})

Just make sure your program stays the same. Find out the result first, modify the name of knowledge only, and then update.
When you feel awkward, troublesome and inefficient about any operation of the database, you should go back and think about whether the structural design of the database can be improved, which is applicable to both relational and non-relational databases.http://www.cnblogs.com/mokafamily/p/4102829.html, you can look at the “1. Normalization and Anti-Normalization” section in this article.