const mongoose = require('mongoose') mongoose.Promise = Promise const models = { Sock: require('./sock.js').schema, Media: require('./media.js').schema, User: require('./user.js').schema, Cart: require('./cart.js').schema, Coupon: require('./coupon.js').schema, } module.exports = function connect(url) { const connection = mongoose.createConnection(url) connection.on('error', console.error.bind(console, 'connection error:')); var sock = connection.model('Sock',models.Sock, 'socks'); 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 coupon = connection.model('Coupon',models.Coupon, 'coupons'); return { sock, media, user, cart, coupon, _connection: connection } }