node.js - node expressjs中怎么配置和组织mongoose模块?
迷茫
迷茫 2017-04-17 13:43:08
0
1
359
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
Ty80
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;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!