在我的模型中,我有这样的东西:
subjects: {
Mathematics: {
questionsanswered: [
"x+2=3, solve for x please",
"How do you write an expression that represents all quadrantal angles?"
],
questionsasked: [
"how to convert sin to cos?",
"factor the trinomial: 3x^2+7x+2"
]
}
}
如您所见,有很多子元素,我完全是 Mongoose 和 Node.js 的初学者,我正在尝试在questionsanswered
数组字段中添加另一个问题(字符串)。我查阅了文档并尝试了
userModel.update({username: username},{$pushAll: { subjects:{Mathematics:{questionsasked:['what is the definition of calculus']}}}},{upsert:true},function(err){
if(err){
console.debug(err);
}else{
console.debug("Successfully added");
}
});
但它说'Modifier $pushAll allowed for arrays only',有人知道如何在questionsanswered
数组中插入另一个元素吗?非常感谢!