I am trying to use populate to return results that are ref to the Stamp model, under the users array of stamps but for some reason it does not return any results when I see in the database a list of stamp ids in the stamps array...
Here is my code:
var selectQuery = "_id name";
var populateQuery = [{path:'stamps', select: selectQuery, model: 'Stamp', }];
User.findOne({_id: userId}).populate(populateQuery).sort({date: -1}).skip(count).limit(100).exec(function(err, results) {
if(err) {
Here is the User Schema
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = mongoose.Schema.Types.ObjectId,
var Stamp = require('../models/stamp.js');
var User = new Schema({
name: { type: String},
stamps: [{ type: ObjectId, ref: 'Stamp' }],
The "query" form of
populate
doesn't take an array as argument, but an object: