我是 Mongoose/nodejs 的新手,我正在努力简单地更新数组中的数组。
这是架构:
var County = new Schema({
_id : Schema.ObjectId,
name : String,
biggestCity : String
});
var Country = new Schema({
_id : Schema.ObjectId,
name : String,
counties : {type: [County], ref: "County"}
});
var Continent = new Schema({
_id : Schema.ObjectId,
countries : {type: [Country], ref: "Country"},
});
这是我一直在尝试的更新代码:
var continents = mongoose.model("Continent");
var update = { "countries.counties.name": newName, "countries.counties.biggestCity": newBiggestCity };
var conditions = { "_id": countryId, "countries.name": countryName, "countries.counties.name": countyName };
var options = { multi: false };
wagers.update(conditions, update, options, function(err, numAffected) {
//callback code...
});
执行此操作时,err 中的错误为“无法使用字符串字段名称'counties' 附加到数组”。这是什么意思?我究竟做错了什么?