You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB
JavaScript

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
}
}