Я импортировал базу данных из файла json и создал эту схему и модель, но db возвращает пустой объект при поиске
т.е. []
, но тот же код работает, если я создаю базу данных с использованием этой схемы
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
mongoose= require("mongoose"),
bodyParser= require("body-parser"),
Registration = require("./models/registration");
//==============
//MONGOOSE CONFIG
//==============
//========================================
mongoose.connect("mongodb://localhost/new");
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
// we're connected!
console.log("CONNECTION TO MONGO SUCCESSFUL")
})
//============
//SOME OTHER PACKAGES
//============
app.set("view engine","ejs");
app.use(express.static('public'));
app.use(bodyParser.urlencoded({extended:true}));
//=============
//ROUTES
//=============
app.get('/',function(req,res){
res.render("landing");
});
app.post('/',function(req,res){
var idnumber = req.body.id;
Registration.find({id:"2019AAPS0334G"}).lean().exec(
function(err,foundArr){
if(err){
console.log(err);
}
else{
console.log(foundArr);
res.render("index",{foundArr:foundArr});
}
}
);
})
//==============
//PORT on which service starts
//==============
var port = process.env.PORT || 31000
app.listen(port, process.env.IP,function(){
console.log("Server started at port:"+ port);
})
var mongoose =require("mongoose");
var registrationSchema = new mongoose.Schema({
id : String,
name : String,
courseid : String,
coursename : String,
midsemdate : String,
midsemtime : String,
compredate : String,
compretime : String,
});
module.exports = mongoose.model("Registration",registrationSchema);
{ "_id" : ObjectId("5e191cee5bd3cc601decba2b"), "id" : "2019A1PS0224G", "name" : "someguy", "courseid" : "CHEM F110", "coursename" : "CHEMISTRY LABORATORY", "section" : "P2", "midsemdate" : "TO BE ANNOUNCED BY IC", "midsemtime" : "TO BE ANNOUNCED BY IC", "compredate" : "TBA", "compretime" : "TBA" }
{ "_id" : ObjectId("5e191cee5bd3cc601decba2c"), "id" : "2019A1PS0224G", "name" : "someguy", "courseid" : "BITS F110", "coursename" : "ENGINEERING GRAPHICS", "section" : "P3", "midsemdate" : "TO BE ANNOUNCED BY IC", "midsemtime" : "TO BE ANNOUNCED BY IC", "compredate" : "14/05/20 (FN)", "compretime" : "9 AM - 12 Noon" }
{ "_id" : ObjectId("5e191cee5bd3cc601decba2d"), "id" : "2019A1PS0224G", "name" : "someguy", "courseid" : "MATH F113", "coursename" : "PROBABILITY AND STATISTICS", "section" : "L4", "midsemdate" : "06/03/20, Friday", "midsemtime" : "2:00 PM- 3:30 PM", "compredate" : "04/05/20 (AN)", "compretime" : "2 PM - 5 PM" }