-
Notifications
You must be signed in to change notification settings - Fork 34
/
db.js
34 lines (29 loc) · 861 Bytes
/
db.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
var Promise = require("bluebird");
var mongoskin = require("mongoskin");
var db;
if (!process.env.MONGODB_URI) {
console.log("Error: No MongoDB instance specified");
process.exit(1);
} else {
// Connect to MongoDB
db = mongoskin.db(process.env.MONGODB_URI, {native_parser: true});
}
// Bind collections
db.bind("projects");
db.bind("machines");
db.bind("experiments");
// Promisify all methods
Object.keys(mongoskin).forEach((key) => {
var value = mongoskin[key];
if (typeof value === "function") {
Promise.promisifyAll(value);
Promise.promisifyAll(value.prototype);
}
});
Promise.promisifyAll(mongoskin);
// Add helper methods to db
db.ObjectID = mongoskin.ObjectID;
db.toObjectID = mongoskin.helper.toObjectID;
db.GridStore = mongoskin.GridStore;
// TODO Make helper functions to contain GridFS in this file
module.exports.db = db;