performance table join with async javascript and mongoose
var asynclib = require('async');
exports.apiFindNutrients = function(req, res) {
    var ndb = req.params.ndb;
    NutrDefModel.find().limit(30).exec(function(error, nutref) {
            asynclib.mapSeries(nutref, function(ref, callback) {
              NutrModel.find({ Nutr_No: ref.Nutr_No, Ndb_No: ndb },
function(error, nutrient) {
                      var result = {
                          Ndb_No: nutrient.Ndb_No,
                          Nutr_Desc: ref.Nutr_Desc,
                      };
                      callback(null, result);
                  }
              });
            }, function (err, result) {
                if (err)
                    console.log('async lib ' + err);
                res.send(result);
            });
        }
    });
};
I want to join two tables with mongoose, i came up with the above solution
but it takes 12 seconds for 70 items in NutrDefModel, when i do limit(30)
it takes 1.5 seconds. I need to improve to under 1 seconds. I am really
new to async javascript and mongoose, i barely understand how async
library works in this solution, what alternetives do i have with
javascript and mongoose.
 
No comments:
Post a Comment