Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoose embedded document query returning null
    text
    copied!<p>I have the following schema :</p> <pre><code>_schema : { Prize : new Schema({ prizeName : { type : String }, thumbnailImage : [ String ], detailImage : [ String ], prizeCategory : [ {type : String, index : true } ], prizeDescription : { type : String }, prizePrice : { type : Number, required : true } }), Game : new Schema ({ roomName : { type : String, required : true }, openTime : { type : Date }, closeTime : { type : Date }, minPlayers : { type : Number }, maxPlayers : { type : Number, required : true }, numberOfPlayers : { type : Number }, winner : { userId : { type : ObjectId, index : true, ref : 'User'} }, prize : [ this.Prize ], tag : [ { type : String, index : true } ], status : { type : Number, index : true }, businessType : { type : Number, required : true, index : true }, mallId : { type : ObjectId, ref : 'Mall' }, registeredPlayers : { type : ObjectId, ref : 'User' } }), Schedule : new Schema ({ _id : ObjectId, time : { type : Date, index : true }, game : [ this.Game ] }), } </code></pre> <p>However when I try to query the game embedded document the object is always null. I'm querying like so:</p> <pre><code>var Schedule = mongoose.model('Schedule', this._schema.Schedule); Schedule.findById({'game._id' : req.params._id}).exec(function(err,gameDetail){...}); </code></pre> <p>Am I doing anything wrong when I declare the schema and models? I have seen numerous examples where people appear to be doing exactly what I'm trying. Any help would be greatly appreciated! Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload