.find 不是一个函数 mongoose + nodejs + express [英] .find is not a function mongoose + nodejs + express
本文介绍了.find 不是一个函数 mongoose + nodejs + express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用猫鼬进行查找,但我明白了
I am trying to do a find with mongoose, but I get this
类型错误:Query.find 不是函数"
"TypeError: Query.find is not a function"
我有这个模型:
// file: ./models/request.js
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var dnSchema = new Schema({
customerId: String,
uuid: String,
get_data: String,
get_scores: String
});
dnSchema.index({ customerId: 1, time: -1 });
module.exports = mongoose.model('dN', dnSchema);
我有这个控制器
var mongoose = require('mongoose');
var dn = mongoose.model('dn');
(...)
var getScores = exports.getScores = function(req, res) {
var Query = new dn();
console.log(Query)
Query.find({}, function(err, example) {
res.status(200).send(example)
});
}
还有这个 index.js
And this index.js
var mongoose = require('mongoose');
mongoose.connect(config.url, function(err, res) {
if(err) {
logger.error('Error connecting to Database ' + process.pid);
throw err;
}
});
var models = require('./models/request')(app, mongoose);
var controllers = require('./controller/request');
var router = express.Router();
router.route('/get_scores')
.get(controllers.getScores);
app.use(router);
var httpServer = http.createServer(app);
httpServer.listen(config.port, function (){
controllers.logIn();
});
我正在尝试做一个简单的 .find,但我可以做到.
I am trying to do a simple .find, but I can do it.
我希望你的帮助伙伴!!
I hope your help mates!!
谢谢你!!
推荐答案
尝试在您的控制器中导入架构并使用该架构.
Try to import the Schema in your controller and use that one.
var dn = require('path to schema file');
(...)
var getScores = exports.getScores = function(req, res) {
dn.find({}, function(err, example) {
res.status(200).send(example)
});
}
这篇关于.find 不是一个函数 mongoose + nodejs + express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文