javascript - mongoose object relationship -


i trying create new access token object. in debugger, can see user._id value returned correctly. when assigned token user field, value of token.user._id undefined , token.user.id garbage value. same behaviour observed after saving token.

exports.create = function(user, client, deviceid, done) {     if (!user) return done(new error('failed create client without user'));     var token = new accesstoken({         user: user._id,         client: client._id,         deviceid: deviceid     });     token.save(function(err) {         if (err) return done(err);         return done(null, token);     }); }; 

with

var token = new accesstoken({     user: user._id,     client: client._id,     deviceid: deviceid }); 

you're assigning user's id user can use token.user. if want access user's id token.user._id should :

var token = new accesstoken({     user: user,     client: client._id,     deviceid: deviceid }); 

but have use .populate('user') when querying access token.user._id


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -