猫鼬位置运算符错误 [英] Mongoose positional operator errors

查看:80
本文介绍了猫鼬位置运算符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在猫鼬中运行这样的命令:

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);
});

但是我收到错误消息:[TypeError:无法调用未定义的方法'path']

however I get the error: [TypeError: Cannot call method 'path' of undefined]

我猜想它与mongoose和$运算符有关,因为它可以在mongodb控制台中工作.

I am guessing it has to do with mongoose and $ operator because it works in the mongodb console.

有什么想法吗?

推荐答案

我也遇到过猫鼬类似的问题,也许编辑您的文章以查看架构.我通过在架构中进行以下修改来解决了问题:<

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}]
});

在工作示例(如下)中的注意事项,我添加了new mongoose.Schema()

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})]
});

您可能需要对架构中的播放列表EmbeddedDoc参数进行此修改.

You probably need to do this modification to your playlist embeddedDoc parameter in your schema.

这篇关于猫鼬位置运算符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆