Moved mongo and memcached connection into a separate module
This commit is contained in:
1 parent
83d05462bf
commit
d636c31940
2 files changed
+40
-35
No files matched your search
@@ -0,0 +1,25 @@
|
||||
config = require './config'
|
||||
mongo = require 'mongodb'
|
||||
Memcached = require 'memcached'
|
||||
|
||||
exports.memcached = new Memcached(config.MEMCACHED_SOCKET)
|
||||
|
||||
# Create MongoDB connections
|
||||
dbserver = new mongo.Server(config.MONGODB_SOCKET, 0, {auto_reconnect: true})
|
||||
tasksCollection = null
|
||||
devicesCollection = null
|
||||
db = new mongo.Db(config.DATABASE_NAME, dbserver, {native_parser:true, safe:true})
|
||||
|
||||
db.open( (err, db) ->
|
||||
db.collection('tasks', (err, collection) ->
|
||||
exports.tasksCollection = collection
|
||||
collection.ensureIndex({device: 1, timestamp: 1}, (err) ->
|
||||
)
|
||||
)
|
||||
|
||||
db.collection('devices', (err, collection) ->
|
||||
exports.devicesCollection = collection
|
||||
)
|
||||
)
|
||||
|
||||
exports.mongo = mongo
|
||||
Reference in new issue
Block a user