1
嵌套集合我有这样的收集和架构:更新/更新插入/插入到流星和MongoDB中
Words = new Mongo.Collection("words");
WordsSchema = new SimpleSchema({
date: {
type: String
},
owner: {
type: String
},
entries: {
type: [Entry]
}
});
Entry = new SimpleSchema({
post: {
type: String
},
elapsed_time: {
type: Number
},
createdAt: {
type: Date
}
});
Words.attachSchema(WordsSchema);
我只是试图将条目添加到这个集合,通过UPSERT(或更新与更新插入=真),像这样:
Words.update({
date: today,
owner: Meteor.userId()
}, {
$push: {
entries: { post: post, elapsed_time: elapsed_time, createdAt: new Date() }
}
}, {
upsert: true
});
即如果与日期(对象=今天存储为 'YYYY-MM-DD')和所有者= userId的存在,它只是增加了具体的条目。
但我做错了,因为我得到的错误:“条目是必需的”。
任何帮助或想法非常感谢!谢谢。