2
我正在使用mongodb在節點js中構建應用程序。我使用貓鼬作爲ODM。 問題是我有很多靜態函數附加到模式的貓鼬模型。在貓鼬中組織靜態函數
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var userSchema = new Schema({
profile: {
firstName: { type: String },
lastName: { type: String }
},
auth:{
username:{ type: String },
password:{ type: String }
},
account:{
status:{ type: Boolean, default: false }
}
});
userSchema.statics.function1 = function(params, callback){
//some operation
}
userSchema.statics.function2 = function(params, callback){
//some operation
}
userSchema.statics.function3 = function(params, callback){
//some operation
}
userSchema.statics.function4 = function(params, callback){
//some operation
}
//.... upto 50 to 70 static functions
var User = mongoose.model('User', userSchema);
module.exports = User;
有沒有寫在另一個文件(或模塊)和進口這些功能,並將它們連接到架構的方式。 謝謝。