forked from rohenaz/bmap-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.ts
49 lines (42 loc) · 800 Bytes
/
db.ts
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
43
44
45
46
47
48
49
import mongo from 'mongodb'
const MongoClient = mongo.MongoClient
let client = null
let db = null
const getDbo = async () => {
if (db) {
return db
} else {
try {
client = await MongoClient.connect(process.env.MONGO_URL, {
poolSize: 10,
useUnifiedTopology: true,
useNewUrlParser: true,
})
db = client.db('bmap')
return db
} catch (e) {
throw e
}
}
}
const closeDb = async () => {
if (client !== null) {
await client.close()
client = null
}
}
export { closeDb, getDbo }
// db.c.createIndex({
// "MAP.app": 1,
// "MAP.type": 1,
// })
// db.c.createIndex({
// "MAP.app": 1,
// "MAP.type": 1,
// "blk.t": -1,
// })
// db.c.createIndex({
// "MAP.app": 1,
// "MAP.type": 1,
// "blk.i": -1,
// })