Mongo/Mongoose查询结果中缺少字段 [英] Missing field in Mongo/Mongoose Query Results

查看:149
本文介绍了Mongo/Mongoose查询结果中缺少字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将节点应用程序发布到我的Raspberrypi(与专用服务器XD最接近的节点)上,以便我的一些朋友测试我编写的一个小型Web应用程序,但是出于某种原因,查询之一是在ide上运行时,在pi上无法正常工作(云9).

I am trying to publish a node app to my Raspberrypi (the closest thing I have to a dedicated server XD ) for some of my friends to test a little web-app I wrote, but for some reason one of the queries is not working correctly on the pi when it does on my ide (cloud 9).

以下是架构:

var campaignSchema = new Schema({
    gameMaster: {
        type: Schema.Types.ObjectId,
        ref: "Users"
    },
    players: [{
       type: Schema.Types.ObjectId ,
      ref: "Users"
    }],
    name: String,
    gameSystem: String,
    subSystem: String
});

这是查询:

db.Campaign.findOne({'_id' : req.params.campaign}, 'gameMaster players')
.exec(function(err, campaign){
    console.log(campaign);
});

结果为:

{ 
    _id: 556f09195865094845a0d522, 
    players: [] 
}

但是在mongo中执行db.campaigns.find({})会导致:

But doing db.campaigns.find({}) in mongo results in:

{ 
    "_id" : ObjectId("556f09195865094845a0d522"), 
    "gameMaster" : ObjectId("556d1daf4b9b697213468827"), 
    "gameSystem" : "Nwodv2", 
    "subSystem" : "Demon", 
    "name" : "Baltimore", 
    "players" : [ ], 
    "__v" : 0 
}

我觉得我一定会丢失一些东西……虽然我不知道如何解决这个问题,但我在字段上没有限制的情况下尝试了查询,但是它仍然省略了gameMaster字段...

I feel like I must be missing something... I don't have any idea how to resolve this though, I tried the query without a limiter on the fields, but it still omitted the gameMaster field...

应要求在此处创建Campaign对象

at request here is the creation of the Campaign object

var campaign = new db.Campaign({
        gameMaster: userid,
        gameSystem: req.body.system,
        subSystem: req.body.subsystem,
        name: req.body.name
    });

更令人困惑的是,此查询有效:

To be further confounding, this query works:

db.Campaign.findOne({'_id' : req.params.campaign}, 
    '_id name gameSystem subSystem gameMaster players') 
    .populate('gameMaster', '_id displayName')
    .populate('players', '_id displayName')
    .exec(function(err, campaign) {
      //gameMaster is valid here with the id and displayName populated...
    });

推荐答案

https://github.com com/Automattic/mongoose/issues/3020

如果其他任何人遇到此问题.我发现此错误报告可以解释问题的原因,这显然与如何安装新的Mongoose 4有关.

If anyone else is having this issue. I found this bug report that can explain the cause of the problem, it is related to how you install the new mongoose 4 apparently.

这篇关于Mongo/Mongoose查询结果中缺少字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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