Add index against `owner` field
Opened this issue · 1 comments
rtclauss commented
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
Might need to catch an exception if the index already exists