IBMStockTrader/trade-history

Add index against `owner` field

Opened this issue · 1 comments

An index against the owner field in Mongo/DocumentDB really helps performance. here is the mongo shell command to create the index:

use stocktraderhistory;
db.test_collection.createIndex({"owner":1},{name:"owner_asc"})

We should be able to create this index programmatically in MongoConnector by changing the constructor from:

    public MongoConnector(MongoClient mClient, String mongoDatabase, String mongoCollection) {
        mongoClient = mClient;
        database = mongoClient.getDatabase(mongoDatabase);
        database.createCollection(mongoCollection);
        tradesCollection = database.getCollection(mongoCollection);
    }

to

    public MongoConnector(MongoClient mClient, String mongoDatabase, String mongoCollection) {
        mongoClient = mClient;
        database = mongoClient.getDatabase(mongoDatabase);
        database.createCollection(mongoCollection);
        tradesCollection = database.getCollection(mongoCollection);
        tradesCollection.createIndex(Indexes.ascending("owner"));
    }

Might need to catch an exception if the index already exists