const mongoose = require('mongoose') mongoose.Promise = Promise const models = { News: require('./news.js').schema, Sock: require('./sock.js').schema, Tag: require('./tag.js').schema, Media: require('./media.js').schema, User: require('./user.js').schema, Cart: require('./cart.js').schema, Coupon: require('./coupon.js').schema, Message: require('./importantMessages.js').schema } module.exports = function connect(url) { const connection = mongoose.createConnection(url) connection.on('error', console.error.bind(console, 'connection error:')); var news = connection.model('News',models.News, 'news'); var sock = connection.model('Sock',models.Sock, 'socks'); var tag = connection.model('Tag',models.Tag, 'tags'); var media = connection.model('Media',models.Media, 'medias'); var user = connection.model('User',models.User, 'users'); var cart = connection.model('Cart',models.Cart, 'carts'); var message = connection.model('ImportantMessage',models.Message, 'messages'); var coupon = connection.model('Coupon',models.Coupon, 'coupons'); return { news, sock, tag, media, user, cart, message, coupon, _connection: connection } }