node.js - Mongoose.js - population and additional fields? -


i want add additional data usermodel watchedmovies , have following schema:

let userschema = new schema({   watchedmovies: [{     type: schema.types.objectid,     ref: 'movie'   }] }) 

and:

let movieschema = new schema({   title: string }) 

i wondering possible add additional fields watchedmovies object , store along objectid? add watchedat date when i'm populating watchedmovies usermodel.find().populate('watchedmovies', 'title').exec(...) like:

{   _id: objectid(userid),   watchedmovies: [{     _id: objectid(...),     title: 'some title',     watchedat: timestamp   }] } 

watchedat attribute specifies when (date object) reference added usermodel

is possible mongoose , how should change schema?

thank you

change schema to

let userschema = new schema({   watchedmovies: [{     movie: {         type: schema.types.objectid,         ref: 'movie'     },     watchedat: date   }] }) 

then can populate .populate('watchedmovies.movie')


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -