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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -