IBMStockTrader / trade-history

Microservice that keeps a detailed history of all stock trades
Apache License 2.0
1 stars 19 forks source link

Add index against `owner` field #65

Open rtclauss opened 2 years ago

rtclauss commented 2 years ago

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"));
    }
rtclauss commented 2 years ago

Might need to catch an exception if the index already exists