问题
I am trying to run a command like this in mongoose:
Song.update({url: s.url, "playlist.playlist_id": pl._id}, {$set: {"playlist.$.position": 505050}}, function(er, da) {
console.log("song on playlist lets change position");
console.log(er);
console.log(da);
});
however I get the error: [TypeError: Cannot call method 'path' of undefined]
I am guessing it has to do with mongoose and $ operator because it works in the mongodb console.
Any ideas?
回答1:
I had similar issue with mongoose also, maybe edit your post to see the schema. I fixed my problem by doing the following modification in my schema:<
var Result = new Schema({
id : Number,
detailResult : [detailRef],
simpleResult : [{id: ObjectId, unit: String, value: Number, completed: Boolean}]
});
Notice in the working example (below), I added new mongoose.Schema()
var Result = new Schema({
id : Number,
detailResult : [detailRef],
simpleResult : [new mongoose.Schema({id: ObjectId, unit: String, value: Number, completed: Boolean})]
});
You probably need to do this modification to your playlist embeddedDoc parameter in your schema.
来源:https://stackoverflow.com/questions/8874617/mongoose-positional-operator-errors