Ausführung mehrerer Mungo Abfragen

Ich bin mit Knoten und mongoose zum ausführen von Abfragen in meine mongodb. Ich habe eine Reihe von 3 Abfragen, dass ich laufen wie folgt :

company.find({ 'shortName': eval("/" + req.params.query + "/i"), logoFileName : {$exists : true} }, function(err, b){
        if(err){
            console.log('brand query not found! ' + err);
            res.send(500, "Something broke!")
        }
        else{
            console.log("length of b : " + b.length)
            if(b.length>1){
                res.render('index', {
                    potentialBrands : b
                })
            }
            else{
                var brandResults  = b[0];   


            var industryQuery = company.find({GICSIndName: eval("'"+brandResults.GICSIndName+"'")}).sort({marketCap: -1}).limit(10);

            industryQuery.exec(function(err, industry){
                if(err){
                    console.log("There was an error! : " + err)
                    res.send(500, "Something broke!")
                }
                //if the colors have yet to be defined
                if(typeof brandResults.associatedColors[0] !== 'undefined'){
                    var colorQuery = company.find({'associatedColors.colorFamily': eval("'" + brandResults.associatedColors[0].colorFamily + "'") });

                    colorQuery.exec(function(err, colors){
                        if(err){
                            console.log("There was an error! : " + err)
                            res.send(500, "Something broke!")
                        }
                        console.log(colors);
                        res.render('brand',{
                            brandResult : brandResults,
                            industryResult: industry,
                            colorResult: colors,
                            queryName : req.params.query
                        });
                    })
                }
                else{
                    res.send(500, "Something broke!")
                }
            })

Meine aktuelle Struktur scheint ziemlich ineffizient, und ich Frage mich, ob es etwas in mongo oder Mungo gebaut ist, dass für die Behandlung solcher Anfragen.

  • Was ist ineffizient? Sie könnten versuchen, codereview.stackexchange.com.
  • Ich nahm an, er meint ineffizient, weil er die Abfragen der gleichen Kollektion, aber zu tun hat 3 separate Abfragen, um so zu tun.
InformationsquelleAutor Airswoop1 | 2013-12-20
Schreibe einen Kommentar