-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongoose.js
43 lines (34 loc) · 924 Bytes
/
mongoose.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* 连接多个数据库
* @type {{hallDB: *, weChatAppDB: *}|*}
* bohong
*/
const mongoose = require('mongoose')
//连接数据库 weChatApp
const DBURL = 'mongodb://47.101.181.98:27017/weChatApp'
const weChatAppDB = mongoose.createConnection(DBURL,{useNewUrlParser:true,server: {
auto_reconnect: true,
poolSize: 10
}})
weChatAppDB.on('error', () => {
console.log('Mongoose connection error')
});
weChatAppDB.on('connected', () => {
console.log('连接成功weChatApp')
});
//连接数据库2 hall
const DBURLHALL = 'mongodb://47.101.181.98:27017/hall'
const hallDB = mongoose.createConnection(DBURLHALL,{useNewUrlParser:true,server: {
auto_reconnect: true,
poolSize: 10
}})
hallDB.on('error', () => {
console.log('Mongoose connection error')
});
hallDB.on('connected', () => {
console.log('连接成功hall')
});
module.exports = {
weChatAppDB,
hallDB
}