populate and select mongoose code example
Example 1: mongoos populate a ref
const storySchema = Schema({
authors: [{ type: Schema.Types.ObjectId, ref: 'Person' }],
title: String
});
// Later
const story = await Story.findOne({ title: 'Casino Royale' }).populate('authors');
story.authors; // `[]`
Example 2: populate mongoose array select
User.findById(id).populate({
path: 'contacts.user',
select: 'email'
})