我有一个查询,我试图将多个对象推入一个数组。这是我的代码:
var userSchema = mongoose.Schema({
name : String,
created : {
type : Date,
default : Date.now
},
modified : Date,
phone: [{
kind: String,
number: String
}],
pic : String,
});
var phones = [
{"kind":"Cell","number":"343-343-3434"},
{"kind":"Work","number":"454-454-4545"}
];
User.findByIdAndUpdate(
req.params.user_id,
{"$push": {"phone": {"$each": phones}}},
{safe: true, upsert: true},
function(err) {
if (err) {
console.log('ERROR = ' + err);
}
}
);
我收到此错误:
ERROR = MongoError: Can't canonicalize query: BadValue unknown top level operator: $push
我做错了什么?