That is exactly what I did to resolve it. Thanks for your reply.

On Sun, Mar 15, 2015 at 3:27 PM, zladuric <[email protected]> wrote:

> Your query is also not optimal.
>
> As I wrote on your SO question, you should do something like this:
>
>     User.find({
>         // setup query
>         username: {$in: req.user.followed_users}
>     },
>     {
>         // setup fields to return
>         username: true,
>         profilepic: true,
>         userbio: true
>       },
>       // callback
>       function (err, followedUsers) {
>         res.json(followedUsers); // or render or whatever.
>       });
>   },
>
> On Saturday, March 14, 2015 at 3:15:26 PM UTC+1, Aryak Sengupta wrote:
>>
>> Hi Angel,
>>
>> Thanks for your reply.I resolved it. What you mentioned in the end is
>> absolutely true.
>>
>>
>> *"Understanding callbacks/async is the price to pay to live at Node.js
>> paradise ;-"*
>> I want to dive in deeper to async callbacks. Can you refer me some
>> resources which will help me to grasp the concept properly.
>>
>> Thanks again.
>>
>>
>>
>> On Sat, Mar 14, 2015 at 7:09 PM, Angel Java Lopez <[email protected]>
>> wrote:
>>
>>> Hi!
>>>
>>> I didn't run this code, but maybe is a solution
>>>
>>> router.get('/account',isAuthenticated, function(req,res){
>>>    var following_users_details = [];
>>>    var i = 0;
>>>
>>>    getOneUser();
>>>
>>>    function getOneUser() {
>>>
>>>         var following_user = req.user.following_users[i++];
>>>
>>>         if (!following_user) {
>>>             res.render('users/userAccount',{user:req.user,
>>> following_users_details:following_users_details });
>>>             return;
>>>         }
>>>
>>>         User.findOne({'username' : following_user },
>>>             function(err,user)
>>>             {
>>>                 if (!err)
>>>                     following_users_details.push({
>>>                         username: user.username,
>>>                         profilepic : user.photo,
>>>                         userbio : user.bio
>>>                     });
>>>
>>>                 setTimeout(getOneUser, 0);
>>>             });
>>>     }
>>> });
>>>
>>> The original code returned a result BEFORE the find one user executes
>>> the callback.
>>>
>>> The above code retrieves one user, and then, in the callback, invoke the
>>> same function to retrieve another user. It should be better solutions, but
>>> I hope this code works.
>>>
>>> Understanding callbacks/async is the price to pay to live at Node.js
>>> paradise ;-)
>>>
>>> Angel "Java" Lopez
>>> @ajlopez
>>>
>>>
>>> On Sat, Mar 14, 2015 at 6:55 AM, Aryak Sengupta <[email protected]>
>>> wrote:
>>>
>>>> *I am trying to create an array of Key-Value pairs dynamically with a
>>>> document from a MongoDB database .*
>>>>
>>>> I have posted my question on Stack Overflow but still I can't figure
>>>> out where I am going wrong. This is my question ->
>>>>
>>>> *Creating an array of key-value pairs(fetched from a mongoDB database)
>>>> dynamically*
>>>> <http://stackoverflow.com/questions/29047069/creating-an-array-of-key-value-pairsfetched-from-a-mongodb-database-dynamicall>
>>>>
>>>> Any help will be appreciated,
>>>> Thank You.
>>>>
>>>> --
>>>> Job board: http://jobs.nodejs.org/
>>>> New group rules: https://gist.github.com/othiym23/9886289#file-
>>>> moderation-policy-md
>>>> Old group rules: https://github.com/joyent/node/wiki/Mailing-List-
>>>> Posting-Guidelines
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "nodejs" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/nodejs/CALTbq1w%2B5Wz-RWmtSWADc%3Dn%2BF9tP4aYOqs-_S%
>>>> 3D7jbeBaawerKg%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/nodejs/CALTbq1w%2B5Wz-RWmtSWADc%3Dn%2BF9tP4aYOqs-_S%3D7jbeBaawerKg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>> Job board: http://jobs.nodejs.org/
>>> New group rules: https://gist.github.com/othiym23/9886289#file-
>>> moderation-policy-md
>>> Old group rules: https://github.com/joyent/node/wiki/Mailing-List-
>>> Posting-Guidelines
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "nodejs" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/nodejs/CAMs%2BDqK0HCDGPPwt7G4mGXjdtnrRGyhq
>>> ooQC6P2FhGvMD3YFew%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/nodejs/CAMs%2BDqK0HCDGPPwt7G4mGXjdtnrRGyhqooQC6P2FhGvMD3YFew%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/ed412464-5391-4470-9710-5a695b4b0312%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/ed412464-5391-4470-9710-5a695b4b0312%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CALTbq1ya%3Do9xxAroOY%2BUnONwGgSAe%3DcuPLG7pK65XJPUYn8w7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to