node.js - Objects not being passed correctly -


a waterfall function being called, 1 of inside functions taking array of user docs , trying find if user himself or friend of user. based on these 2 things, want return user docs each "me" being true/false , "friend" being doc/false. doc not true. however, result getting incorrect.

here code:

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);     }); } 

this result i'm getting:

[ { 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 } ] 

pass users directly async.mapseries call instead of wrapping in array brackets:

async.mapseries(users, function(user, next) { 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -