Mongoose populates field with null -
i have mongoose schema:
mongoose.schema({ state: { type: { action: 'string' , user: {type: mongoose.schema.types.objectid, ref: 'user'}, at: 'date' }, default: {} }, log: [{ action: 'string' , user: {type: mongoose.schema.types.objectid, ref: 'user'}, at: 'date' }] })
trying populate it
model.findbyid(id).populate('state.user').populate('log.user').exec(cb)
in query result "user" field of log items populated correctly and "state.user" null. can problem?
for simple embedded objects state
, define structure without using type
:
mongoose.schema({ state: { action: 'string' , user: {type: mongoose.schema.types.objectid, ref: 'user'}, at: 'date' }, log: [{ action: 'string' , user: {type: mongoose.schema.types.objectid, ref: 'user'}, at: 'date' }] })
populate('state.user')
should work fine that.
Comments
Post a Comment