现在的数据结构是这样的
course:{
name:String,
chapter: [{
name: String,
knowledge: [{
name: String,
exam: [{
name: String,
}]
}]
}]
}
要想修改knowledge.name,修改语句该怎么写?之前在修改chapter.name时我是这样写的
Course.update({
"chapter._id": req.body.id
}, {
$set: {
"chapter.$.name": name, //名称
}
})
.exec(function(err, num) {
});
不知道在修改第三级嵌套文档时,$定位符改怎么使用。
Actually, it’s complicated to think about. Nested queries, nested modifications, etc. If you find nodes layer by layer, the efficiency is not very high.
Document databases, to put it bluntly, are always a string of strings in a json-like format, no matter how deep the nesting is.
The fastest and most direct way is as follows:
Just make sure your program remains unchanged. Find the results first, modify only the name of the knowledge, and then update.
When any database operation feels awkward, troublesome, and inefficient, you should look back and think about whether the structural design of the database can be improved. This applies to both relational and non-relational databases. http://www.cnblogs.com/mokafamily/p/4102829.html, you can take a look at the section "1. Normalization and de-normalization" in this article