My schema is as below
Sectionschema
var SectionSchema = new Schema({ name: String, documents : { type : [{ type: Schema.ObjectId, ref: 'Document' }] } } } DocumentSchema
var DocumentSchema = new Schema({ name: String, extension: String, access: String, //private,public folderName : String, bucketName : String, desc: String }); Api.js
exports.section = function(req, res, next, id) { var fieldSelection = { _id: 1, name: 1, documents : 1 }; var populateArray = []; populateArray.push('documents'); Section.findOne({ _id: id }, fieldSelection) .populate(populateArray) .exec(function(err, section) { if (err) return next(err); if (!section) return next(new Error('Failed to load Section ' + id)); // Found the section!! Set it in request context. req.section = section; next(); }); } If I go this way, I have the 'documents' object is []. However if I remove, "populateArray.push('documents');" then I get documents:['5adfsadf525sdfsdfsdfssdfsd'] -- some object Id (atleast)
Please let me know the way I need to populate.
Thanks.