正在调用瀑布函数,其中一个内部函数采用一组用户文档并尝试查找他们是用户本人还是用户的朋友。基于这两件事,我想返回用户文档,每个用“me”为true / false,“friend”为doc / false。医生本身并不属实。但是,我得到的结果是不正确的。
以下是代码:
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 } ]
答案 0 :(得分:1)
将users
直接传递到async.mapSeries
来电,而不是将其包装在数组括号中:
async.mapSeries(users, function(user, next) {