Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require('mongoose');
- const Schema = mongoose.Schema;
- module.exports = (cfg) => {
- console.log('Initializing MongoDB module')
- const uri = `mongodb://${cfg.host}:${cfg.port}/${cfg.name}`;
- mongoose.connect(uri, {
- promiseLibrary: global.Promise
- }).then(() => {
- console.log('MongoDB connection is initialized');
- }).catch(e => {
- console.log('Couldn\'t connect to MongoDB');
- process.exit();
- });
- const userSchema = new Schema({
- username: { type: String, required: true, index: { unique: true } },
- password: { type: String, required: true },
- avatar: { type: String },
- firstLogin: { type: Date, default: Date.now }
- });
- const chatSchema = new Schema({
- username: String,
- message: String,
- date: Date
- });
- this.User = mongoose.model('User', userSchema);
- this.Chat = mongoose.model('Chat', chatSchema);
- this.db = mongoose.connection;
- return this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement