मेरे पास वर्तमान में मेरे मोंगोस/नोडजेएस अनुप्रयोग के लिए /models/models.js फ़ाइल में मेरे सभी मॉडल (स्कीमा परिभाषाएं) हैं।मोंगोस और नोडजेएस परियोजना का फ़ाइल संरचना
मैं जैसे विभिन्न फाइलों में अलग इन तोड़ने के लिए करना चाहते हैं: user_account.js, profile.js, आदि हालांकि मैं ऐसा करने के लिए के रूप में मेरे नियंत्रकों तोड़ने के लिए और "मॉड्यूल नहीं मिल सकता है" वापस रिपोर्ट एक बार नहीं कर पा रहे मैं इन वर्गों को अलग करता हूं।
/MyProject
/controllers
user.js
foo.js
bar.js
// ... etc, etc
/models
models.js
server.js
मेरी models.js फ़ाइल की सामग्री को इस तरह दिखता है:
मेरे परियोजना संरचना इस प्रकार है
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
mongoose.connect('mongodb://localhost/mydb');
var UserAccount = new Schema({
user_name : { type: String, required: true, lowercase: true, trim: true, index: { unique: true } },
password : { type: String, required: true },
date_created : { type: Date, required: true, default: Date.now }
});
var Product = new Schema({
upc : { type: String, required: true, index: { unique: true } },
description : { type: String, trim: true },
size_weight : { type: String, trim: true }
});
मेरे user.js फ़ाइल (नियंत्रक) इस तरह दिखता है:
var mongoose = require('mongoose'),
UserAccount = mongoose.model('user_account', UserAccount);
exports.create = function(req, res, next) {
var username = req.body.username;
var password = req.body.password;
// Do epic sh...what?! :)
}
मैं स्कीमा परिभाषा को कई फ़ाइलों में कैसे तोड़ सकता हूं और इसे मेरे समोच्च से भी संदर्भित कर सकता हूं ller? जब मैं इसे संदर्भ है (के बाद स्कीमा एक नई फ़ाइल में है) मैं इस त्रुटि मिलती है:
* त्रुटि: स्कीमा मॉडल के लिए "USER_ACCOUNT" पंजीकृत नहीं किया गया है *
विचार।?
मैं नेवला-गोंद मॉड्यूल है जो आपके नेवला मॉडल की संरचना में मदद करता है लिखा है:: https: // आवश्यक FS की आवश्यकता होती है इस प्रकार है
अब आप अपने सभी मॉडलों के कॉल कर सकते हैं जोड़ना सुनिश्चित करें github.com/xpepermint/mongoose-glue – xpepermint