Home / All Articles / how to pass multiple collections query in single route in node js ?

how to pass multiple collections query in single route in node js ?


var with_title = config.with_title;
var top_destinations_in_the_us_result;
var people_search_for_result;
var recommended_estinations_result;
var us_beach_vacation_destinations_result;
var us_solo_vacation_destinations_result;
var us_family_vacation_destinations_result;

//@ Tripinn index/home page.
exports.home = function(req, res) {

async.parallel([
//Load user Data
function(callback) {
var top_destinations = 'Top Destinations in The US';
trpn_city_pages_category_relation.find({selected_categories:top_destinations.trim() },function(err, top_destinations_in_the_us) {
if (err) return callback(err);
top_destinations_in_the_us_result = top_destinations_in_the_us;
//console.log(top_destinations_in_the_us_result);
callback();
});
},
function(callback) {
var people_search_for = 'People Search For';
trpn_city_pages_category_relation.find({selected_categories:people_search_for.trim() },function(err, people_search_for) {
if (err) return callback(err);
people_search_for_result = people_search_for;
callback();
});
},
function(callback) {
var recommended_estinations = 'Recommended Destinations';
trpn_city_pages_category_relation.find({selected_categories:recommended_estinations.trim() },function(err, recommended_estinations) {
if (err) return callback(err);
recommended_estinations_result = recommended_estinations;
callback();
});
},
function(callback) {
var us_beach_vacation_destinations = 'US Beach Vacation Destinations';
trpn_city_pages_category_relation.find({selected_categories:us_beach_vacation_destinations.trim() },function(err, us_beach_vacation_destinations) {
if (err) return callback(err);
us_beach_vacation_destinations_result = us_beach_vacation_destinations;
//console.log(us_beach_vacation_destinations_result);
callback();
});
},
], function(err) { //This function gets called after the two tasks have called their "task callbacks"
if (err) return next(err); //If an error occurred, we let express handle it by calling the `next` function
//Here `locals` will be an object with `user` and `posts` keys
//Example: `locals = {user: ..., posts: [...]}`
//res.render('index.ejs', {userdata: locals.user,postdata: locals.posts})
res.render('index',{title: 'Book Cheap Flights, Hotels & Vacation Rentals | '+ with_title, canonical : '', top_destinations:config.top_destinations,top_usa_beach:config.top_usa_beach,trending_destinations:config.trending_destinations, top_destinations_in_the_us_result:top_destinations_in_the_us_result, people_search_for_result: people_search_for_result,recommended_estinations_result: recommended_estinations_result, us_beach_vacation_destinations_result: us_beach_vacation_destinations_result);
});
};

About admin

Check Also

Schema Markup for eCommerce Websites

Each time someone searches a particular product online, they end up on a SERP that …

Leave a Reply

Your email address will not be published. Required fields are marked *