gpt4 book ai didi

node.js - 回调未在nodejs中获取记录

转载 作者:太空宇宙 更新时间:2023-11-03 23:21:19 25 4
gpt4 key购买 nike

我想在postman中传递电子邮件,并希望将获取的json数据打印到控制台。但它没有获取任何数据。所以帮我解决这个问题

mongoconnect.js

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
var dbo=null;

exports.connection=function(){
if(dbo!=null) return

MongoClient.connect(url, function(err, db) {
if (err) throw err;
dbo = db.db("hospital_api");

});
}

var get = function (){
return dbo;
}

exports.email=function(r){
get().dbo.collection("doctor").find({"email":r}).toArray(function(err,result)
{
if(err) throw err;
console.log(result)
return result;
})
}

医生.js

var express = require('express');
var router = express.Router();

var bodyParser = require("body-parser");
var validator = require('validator');
var mongo= require('./mongoconnect')
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
router.post('/',function(req,res)
{
d=mongo.email(req.body.email)
console.log(d);
})

module.exports = router;

最佳答案

export.email 中,您有一个拼写错误

exports.email = function(r) {
get().collection("doctor").find({"email":r}) // no ".dbo" after get()

关于node.js - 回调未在nodejs中获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49431419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com