【发布时间】:2012-04-12 23:21:21
【问题描述】:
我正在尝试将嵌入文档添加到现有文档字段。我通过搜索找到了one fitting answer,但我遇到了错误。我正在使用 node.js、Express 和 Mongoose。
我的数据库架构:
var entry = new Schema({
name : { type : String, required : true},
description : { type : String, default: ""},
});
var compo = new Schema({
name : String,
description : String,
entries : [entry]
});
我正在尝试使用以下代码更新条目数组
var entry = new entryModel();
entry.name = "new name";
entry.description= "new description";
compoModel.findOne(query, function (err, item) {
if (item) {
item.entries.push(entry);
item.save(function (err) {
if (!err) {
log.debug('Entry added successfully.');
} else {
log.error("Mongoose couldn't save entry: " + err);
}
});
}
});
它产生一个错误:TypeError: Object.keys called on non-object
我错过了什么?
【问题讨论】: