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

user8459
1#
user8459 Published in September 19, 2018, 11:12 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);
    }
});
share|improve this question
  • It is not very clear what exact question you're asking for help with. Can you please state exactly what problem you have and what you want help with? – jfriend00 Apr 16 at 21:59
  • In first query which give me all th user based on location After that i process the users array which return by first query, and get offers related to that user from another query but try to put offers result in user data Offers in users array which return in response give me blank. Please help try to understand... – Rohit Parihar Apr 17 at 3:54
  • Simply I want to return offers in user data which is result of first query and offers are result of second query at the time when I process first query data. – Rohit Parihar Apr 17 at 4:02

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO