Skip to content

Commit

Permalink
db/mongodb: Add index creation on connect
Browse files Browse the repository at this point in the history
_ref: #885
  • Loading branch information
sogehige committed Apr 3, 2018
1 parent 5a0a3bd commit b4a5b19
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libs/databases/mongodb.js
Expand Up @@ -24,6 +24,16 @@ class IMongoDB extends Interface {

async connect () {
this.client = await client.connect(config.database.mongodb.url, { poolSize: _.get(config, 'database.mongodb.poolSize', 5) })

// create indexes
let db = this.client.db(this.dbName)
await db.collection('users.bits').createIndex('timestamp')
await db.collection('users.tips').createIndex('timestamp')
await db.collection('users').createIndex('username')
await db.collection('cache').createIndex('key')
await db.collection('api.stats').createIndex('timestamp')
await db.collection('stats').createIndex('whenOnline')

this.connected = true
}

Expand Down

0 comments on commit b4a5b19

Please sign in to comment.