对于这个控制器,我只是试图返回集合的所有结果。有一个项目在道具集合,但由于某种原因,我一直得到一个未定义的错误。
TypeError: Cannot call method 'find' of undefined
这是我的server.js文件:'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
passport = require('passport'),
logger = require('mean-logger');
/**
* Main application entry file.
* Please note that the order of loading is important.
*/
// Initializing system variables
var config = require('./server/config/config');
var db = mongoose.connect(config.db);
// Bootstrap Models, Dependencies, Routes and the app as an express app
var app = require('./server/config/system/bootstrap')(passport, db);
// Return all results.
app.get('/all', function(req, res) {
var d = db.prop.find();
res.json(d);
});
// Start the app by listening on <port>, optional hostname
app.listen(config.port, config.hostname);
// Initializing logger
logger.init(app, passport, mongoose);
// Expose app
exports = module.exports = app;
我这一切都错了,我习惯了js与restful控制器。在server.js中设置控制器路由是正确的,但使mongodb调用实际上是在平均堆栈中的模型级别完成的,因此这不起作用是预期的功能。基本上你不需要ajax来查询数据库。只是不习惯这样编程,谢谢你的反馈。