0
我正在使用Mongoose的Angular.js。貓鼬創建錯誤模式
我已經從Angular.js創建了一個模式,並且我將數據插入到同一模式中。 但是當我在MongoDB上運行show collections
時,它顯示後綴爲's'的集合名稱。
例如,我使用架構名稱test
,運行查詢將集合顯示爲tests
。
下面是我使用的代碼:
var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var routes = require('./routes/index');
var users = require('./routes/users');
var methodOverride=require('method-override');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(methodOverride(function(req, res){
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
// look in urlencoded POST bodies and delete it
var method = req.body._method
delete req.body._method
return method
}
}));
/* app.use(express.static(path.join(__dirname, 'public'))); */
mongoose.connect('mongodb://localhost/Project');
var custSchema=new mongoose.Schema({
custid : String,
name : String,
password: String
});
var customer= mongoose.model('test',custSchema);
console.dir(customer);
app.use(function(req,res,next){
req.user = customer;
next();
});
//app.use('/', routes.index);
app.get('/', routes.index);
app.get('/show',routes.list);
app.get('/new',routes.list);
//app.post('/show',routes.create);
//app.use('/users', users);
/// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
/// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
謝謝你..但它顯示瞭如何從集合中刪除'_id',但我在收集名稱有問題。 – kawade 2014-10-09 08:39:29
@kawade向上滾動... – robertklep 2014-10-09 08:41:39