Browse Source

add indexes for commong db opperations

activeAddress
Ivan Socolsky 10 years ago
parent
commit
e6dba8c824
  1. 32
      lib/storage.js

32
lib/storage.js

@ -25,12 +25,39 @@ var Storage = function(opts) {
this.db = opts.db;
};
Storage.prototype._createIndexes = function() {
this.db.collection(collections.WALLETS).createIndex({
id: 1
});
this.db.collection(collections.COPAYERS_LOOKUP).createIndex({
copayerId: 1
});
this.db.collection(collections.TXS).createIndex({
walletId: 1,
id: 1,
});
this.db.collection(collections.TXS).createIndex({
walletId: 1,
isPending: 1,
});
this.db.collection(collections.NOTIFICATIONS).createIndex({
walletId: 1,
id: 1,
});
this.db.collection(collections.ADDRESSES).createIndex({
walletId: 1
});
this.db.collection(collections.ADDRESSES).createIndex({
address: 1,
});
};
Storage.prototype.connect = function(opts, cb) {
var self = this;
opts = opts || {};
if (this.db) return cb(null);
if (this.db) return cb();
var config = opts.mongoDb || {};
mongodb.MongoClient.connect(config.uri, function(err, db) {
@ -39,8 +66,9 @@ Storage.prototype.connect = function(opts, cb) {
return cb(err);
}
self.db = db;
self._createIndexes();
console.log('Connection established to ', config.uri);
return cb(null);
return cb();
});
};

Loading…
Cancel
Save