Mongoose positional operator errors

心不动则不痛 提交于 2019-12-22 23:22:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!