正在调用一个瀑布函数,其中一个内部函数获取一组用户文档并尝试查找它们是用户本人还是用户的朋友。基于这两件事,我想返回每个用户文档,“我”是真/假,“朋友”是文档/假。文档本身不是真的。但是,我得到的结果是不正确的。
这是代码:
function(users, callback) {
async.mapSeries([users], function(user, next) {
Friend.findOne({userId: req.signedCookies.userid, friend_id: user}, function(err, friend) {
var me = false;
if (user.id === req.signedCookies.userid) {
console.log('me check');
me = true;
}
if (friend === undefined) {
friend = false;
}
var object = {'user': user, 'friend': friend, 'me': me};
//searchResults.push(object);
next(err, object);
});
}, function(err, searchResults) {
console.log(searchResults);
callback(null, searchResults);
});
}
这是我得到的结果:
[ { user:
[ { firstName: 'test1',
lastName: 'test1s',
email: 'test1@gmail.com',
emailTrue: 'test1@gmail.com',
firstNameTrue: 'Test1',
lastNameTrue: 'teST1s',
password: '$2a$10$irIz5rVSFwGFVjzXqAqdxuxa8wAFoV99FulXykt
',
phone: 2738483282,
birthday: Tue Aug 22 823 20:00:00 GMT-0400 (Eastern Dayli
email_confirmed: true,
date_created: Thu Aug 15 2013 14:54:17 GMT-0400 (Eastern
,
_id: 520d23d9367604cc0d000001,
__v: 0,
socialAccounts: [],
phoneList: [],
emailList: [] },
{ firstName: 'test1',
lastName: 'test1ss',
email: 'test1s@gmail.com',
emailTrue: 'test1s@gmail.com',
firstNameTrue: 'test1',
lastNameTrue: 'test1ss',
password: '$2a$10$kaWYHkg68c4Uti6/DlNVR.N0Ojzo.RnsQ6BARTd
',
phone: 888439348,
birthday: Mon Aug 30 94 20:00:00 GMT-0400 (Eastern Daylig
email_confirmed: true,
date_created: Thu Aug 15 2013 15:11:19 GMT-0400 (Eastern
,
_id: 520d27d7a767bdbc1c000001,
__v: 0,
socialAccounts: [],
phoneList: [],
emailList: [] } ],
friend: false,
me: false } ]