I am simply trying to retrieve all the document from the database but I am getting empty array. I am using express, mongodb and mongoose. Below is my code :
const express = require('express');
const countryArray = require('../models/countryArray');
const router = express.Router();
router.get('/',(req,res)=>{
countryArray.find({ },function (err, result) {
if (err)
return console.error(err);
console.log(result);
});
res.render('index');
});
module.exports = router ;
My Schema is this:
const mongoose = require('mongoose');
var Schema = mongoose.Schema;
var countrySchema = new Schema({
country_id:String,
country_name:String
});
var countryArray = mongoose.model('countryArray',countrySchema);
module.exports = countryArray;
Below is my document in mongodb:
{
"_id": {
"$oid": "5bba2693e7179a6602f63589"
},
"country_id": "1",
"country_name": "India"
}