我想使用meanjs(CRUD)从mongo读取数据。我已经完成了所有必要的映射和安装,但是当我从浏览器(http://localhost:3000/customerQuotes)检查json数据时,我得到的是空数组。
This is Model.js file
'use strict';
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var CustomerquotesSchema = new Schema({
go: {
type: String,
default: '',
trim: true,
required:'Link label is required'
},
show: {
type: String,
trim: true,
default: ''
},
thou: {
type: String,
trim: true,
default: ''
}
});
mongoose.model('Customerquotes', CustomerquotesSchema);
这是controller.js文件
'use strict';
var mongoose = require('mongoose'),
errorHandler = require('./errors.server.controller'),
Customerquotes = mongoose.model('Customerquotes'),
_ = require('lodash');
exports.create = function(req, res) {
var quoteslink = new Customerquotes(req.body);
quoteslink.save(function(err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.json(quoteslink);
}
});
};
exports.read = function(req, res) {
//res.json(req.quoteslink);
};
exports.update = function(req, res) {
};
exports.delete = function(req, res) {
};
exports.list = function(req, res) {
Customerquotes.find().exec(function(err, customerQuotes) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.json(customerQuotes);
}
});
};
这是route.js文件
'use strict';
module.exports = function(app) {
var customerQuotes = require('../../app/controllers/customerquotes.server.controller');
app.route('/customerQuotes')
.get(customerQuotes.list)
.post(customerQuotes.create);
};
答案 0 :(得分:0)
我在express(/ app文件夹)中创建model.js,controller.js和route,js时,通过给出小的(而不是camelcase)命名约定解决了这个问题。很奇怪,这可能是解决方案,但它对我有用:)