1

i want to pass email in postman and want to print the fetched json data to console. but it is not fetching any data. so help me to solve this issue

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;

1 Answer 1

2

In export.email, you have a typo

exports.email = function(r) {
    get().collection("doctor").find({"email":r})  // no ".dbo" after get() 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.