Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


mongoose populate within an object


mongoose populate within an object  using -'node.js,mongoose'

I'm not sure how to populate the sample schema below or if it is even possible.  Can a reference be within an object like below?  If you can, how would you populate it?  E.g. .populate('map_data.location');?  

var sampleSchema = new Schema({
  name: String,
  map_data: [{
    location: {type: Schema.Types.ObjectId, ref: 'location'},
    count: Number
  }]
});


Or will I have to have two separate arrays for location and count like so:

// Locations and counts should act as one object. They should
// Be synced together perfectly.  E.g. locations[i] correlates to counts[i]
locations: [{ type: Schema.Types.ObjectId, ref: 'location'}],
counts: [Number]


I feel like the first solution would be the best, but I'm not entirely sure how to get it working within Mongoose.

Thank you very much for any help!
    

asked Sep 18, 2015 by abhi
0 votes
25 views



Related Hot Questions



Government Jobs Opening


...