comwizz2
comwizz2

Reputation: 106

Missing field in Mongo/Mongoose Query Results

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).

Here is the schema:

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

And here is the query:

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

Which results in :

{ 
    _id: 556f09195865094845a0d522, 
    players: [] 
}

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

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

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...

Edit: 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...
    });

Upvotes: 0

Views: 1740

Answers (1)

comwizz2
comwizz2

Reputation: 106

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

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.

Upvotes: 1

Related Questions