Node.js mongodb+;mongoose:查询未输入。查找函数

Node.js mongodb+;mongoose:查询未输入。查找函数,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我开始使用mongodb和mongoose,但在查询数据库时遇到问题。网上有很多关于我想做的事情的教程,但似乎对我不起作用我的问题是,甚至没有调用.find()函数,也没有显示集合。我有一个名为Subjects的集合,我知道其中有一些值(我在mongodb命令行中手动输入)。我只尝试包含相关的代码,但如果还需要什么,请告诉我。提前谢谢 app.js文件 require('./models/model.js'); var conn = mongoose.createConnection('mong

我开始使用mongodb和mongoose,但在查询数据库时遇到问题。网上有很多关于我想做的事情的教程,但似乎对我不起作用我的问题是,甚至没有调用.find()函数,也没有显示集合。我有一个名为Subjects的集合,我知道其中有一些值(我在mongodb命令行中手动输入)。我只尝试包含相关的代码,但如果还需要什么,请告诉我。提前谢谢

app.js文件

require('./models/model.js');
var conn = mongoose.createConnection('mongodb://localhost/test');
var Subject = mongoose.model('Subjects');

Subject.find( { }, function (err, subjects) {
    if(err) console.log("Error");   // There is no "Error"
    console.log("Made it");         // There is no "Made it"
    console.log(subjects);
});
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var SubjectsSchema = new Schema ({
    subject: { type: String }
});
module.exports = mongoose.model('Subjects', SubjectsSchema);
model.js文件

require('./models/model.js');
var conn = mongoose.createConnection('mongodb://localhost/test');
var Subject = mongoose.model('Subjects');

Subject.find( { }, function (err, subjects) {
    if(err) console.log("Error");   // There is no "Error"
    console.log("Made it");         // There is no "Made it"
    console.log(subjects);
});
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var SubjectsSchema = new Schema ({
    subject: { type: String }
});
module.exports = mongoose.model('Subjects', SubjectsSchema);
调用而不是
mongoose.createconnection
打开默认连接池,该连接池将由使用
mongoose.model
创建的模型使用:

mongoose.connect('mongodb://localhost/test');

非常感谢。另一方面,我没有看到任何主题。在mongo命令行中,我输入db.Subjects.find()并查看输入的内容。但是,当我插入新数据时,
var sub=newsubject({Subject:'some Subject'});sub.save(函数(err){if(err)console.log(err);})我看到了输出。这是怎么回事?试试猫鼬模型('Subjects',subjectschema,'Subjects')取而代之。如果您没有在
model
call.Nice中提供显式名称,Mongoose“有助于”降低大小写并使模型名称复数,以获取集合名称。谢谢我检查了我的mongo db,显然有一个“主题”集合和一个“主题”集合。