Home How to wait query result in nodejs to update another query result
Reply: 0

How to wait query result in nodejs to update another query result

user1672
1#
user1672 Published in July 17, 2018, 12:02 am

Want to add offers query data in current user data to return the users with offers they have created. In response users offers always null

Fetch all user in range distance:

   // Execute Query and Return the Query Results
   query.exec(function(error, associate_users) {
          var array_users = new Array();

          for (var i = 0; i < associate_users.length; i++) {
                var current_user = formatUser(associate_users[i], true);
                var user_id = current_user['user_id'];

                offers_controller.getUserOffers(user_id, latitude, longitude, distance, function(error, result_offers) {

                      current_user['offers'] = result_offers;
                      console.log(result_offers);
                      console.log(current_user); 
                       //Users logs show offers but in array there is no offers in api
          });
          array_users.push(current_user);
       }

       response.json({

           error: false,
           user: array_users,
            message:message.userListed
       });
 }); 

Fetch all offers with associate users in range distance:

var query = offers.find({'type':'Point', offer_by:user_id});

// Execute Query and Return the Query Results
query.exec(function(error, result_offers) {

    if (error) {

        return callback(error, null);
    } else {

        var array_offers = new Array();
        for (var i = 0; i < result_offers.length; i++) {

            array_offers.push(formatOffers(result_offers[i]));
        }
        return callback(null, array_offers);
    }
});
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.35953 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO