栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

猫鼬:通过遍历一系列模型来查找数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

猫鼬:通过遍历一系列模型来查找数据

请检查此代码段,我已为您提供了所需的工作样本。 请检查代码中的注释以更好地理解。

示例工作代码与您所需的类似。

var allRefDatasSchemas = {  RefAllotement: mongoose.model('RefAllotement', RefDataSchema),  RefModeleConstructeur: mongoose.model('RefModeleConstructeur', RefDataSchema),  RefTypeKit: mongoose.model('RefTypeKit', RefDataSchema),  RefTypeUtilisation: mongoose.model('RefTypeUtilisation', RefDataSchema),};var arr = [];for(each in allRefDatasSchemas) {    arr.push(each);}var queue = [    function(callback) {        // pass the ref array and run first query by passing starting index - 0        callback(null, arr, 0)    }];var finalResult = {};var callbackFunc = function(prevModelData, currentIndex, callback) {    allRefDatasSchemas[arr[currentIndex]].find(function(err, result) {        if(err) { console.log(err)        } else { // Your Query //  // I'd like to do something like that : // but this.modelName is null, because it isn't the model // on which the find is done. // arr[currentIndex] will point to  // RefAllotement, RefModeleConstructeur etc. as you required finalResult[arr[currentIndex]] = result // send current result to next interation if required or you can skip // and increment the currentIndex to call next query  callback(null, result, currentIndex + 1)        }    })}for(each in allRefDatasSchemas) {    queue.push(callbackFunc);}async.waterfall(queue, function (err, result) {    // Final object with result of all the queries    console.log('finish', finalResult)});

输出 将采用这种格式

finish { RefAllotement:[        // Result of RefAllotement query    ],    RefModeleConstructeur:[        // Result of RefModeleConstructeur query    ],    RefTypeKit:[        // Result of RefTypeKit query    ],  RefTypeUtilisation:[        // Result of RefTypeUtilisation query    ]}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/448635.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号