我想在postman
中传递电子邮件,并希望将提取的json data
打印到console
。但它不是fetching any data
。所以帮我解决这个问题
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;
})
}
doctor.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;
答案 0 :(得分:2)
在export.email
中,您有一个拼写错误
exports.email = function(r) {
get().collection("doctor").find({"email":r}) // no ".dbo" after get()