var mongoose = require('./config/mongoose.js');
var db = mongoose();
var User = mongoose.model('User');//这里应该是 `User= require('./model/user.server.model.js')`
mongoose.model is a registered user and will not be hung on mongoose. The mongoose in your app.js is the db exported from mongoose.js.
mongoose.js can also organize models in this way
var mongoose = require('mongoose');
var config = require('./config.js');
module.exports = exports = function(){
var db = mongoose.connect(config.uri);
exports.User = require('../models/user.server.model.js');
exports.Other = require('../models/other.server.model.js');
return export;
};
This is how app.js is used
var db = require('./config/mongoose.js')();
var User = db.User;
var Other = db.Other;
mongoose.model
is a registered user and will not be hung on mongoose. The mongoose in yourapp.js
is the db exported frommongoose.js
.mongoose.js can also organize models in this way
This is how app.js is used