我有方法 getFollowing 来获取关注用户的列表
UserSchema.statics.getFollowing = function(data, callback) {
console.log("data: ", data);
this.findOne({
name : data.name
}, function(err, docs) {
if (err)
callback("error " + err)
else if (docs) {
console.log("XXXX", docs.following_count)
mongoose.model('User').findOne({
_id : docs._id
}).populate('following', 'name screen_name avatar _id').exec(function(err, res) {
if (err)
callback(err);
// console.log('The following is %s', res)
});
callback(docs.following);
}
else callback('{"error": "user-not-found"}');
});
}
我只想回调发送到客户端 docs.following 列表我不知道什么时候我 console.log(docs.following) 它打印但是当我回调(docs.following) 它返回错误。
我这样定义 UserSchema
var UserSchema = new Schema({
created_at : { type: Date, default: Date.now }
, name : String
, hashedPass : String
, salt: String
, email : Email
, avatar : {type: String, default: "images/default_profile.png" }
, statuses_count : Number
, screen_name : String
, location : String
, about : String
, followers: [{ type: ObjectId, ref: 'User' }]
, following: [{ type: ObjectId, ref: 'User' }]
, followers_count : Number
, following_count : Number
});