node.js - 如何访问 mongoose find() 外部的变量并返回它
问题描述
我试图在里面调用一个带有 mongoose find() 的函数,然后将返回的值传递给变量 x 但该变量始终为空。我不知道为什么 a 仍然等于“”,即使它在通过 mongoose find() 后应该是另一个值。就好像它在执行 mongoose find() 之前返回了 a 的值。
有没有办法做到这一点?谢谢。
function checkRange(vals) {
let a="";
exports.accountType.find({},function(err,foundAccounts) {
//some if-else statements
// a could be any value depending on the condition
});
return a;
}
var x = checkRange("123");
解决方案
推荐阅读
- graphql - 使用 Graphql 和 Amplify/AppSync 基于先前值的突变
- python - 我如何告诉 Nbconvert:“请使用 pdfLaTeX 代替 XeLaTeX”
- reactjs - 离子 5,反应,电容器,fetchFirestoreCollection 错误
- node.js - 在猫鼬中发布中间件不雾化操作?即使调用 next(err) 仍会创建文档
- php - 为什么 PHP 从 POST 发送的 LONG base64 图像中删除一些字符?
- javascript - Vue 3 - 在 main.js 上导入与 vue.config.js 上的附加数据,加载全局 scss 文件
- python - 将 GIF 或图像添加到 tkinter 的 ScrolledText 小部件。(或另一种使用动画表情的聊天实现,如 BTTV)
- xslt - xslt 3.0 转换帮助 - 按升序对元素进行排序
- arrays - sizeof Calloc 产生错误的输出
- spring-boot - 在 Spring Boot 中定义通用业务属性的最佳实践是什么