private void checkCreateIndex(@Nullable final ClientSession clientSession) { if (!checkedIndexes) { if (collectionIsEmpty(clientSession, filesCollection.withDocumentClass(Document.class).withReadPreference(primary()))) { Document filesIndex = new Document("filename", 1).append("uploadDate", 1); if (!hasIndex(clientSession, filesCollection.withReadPreference(primary()), filesIndex)) { createIndex(clientSession, filesCollection, filesIndex, new IndexOptions()); } Document chunksIndex = new Document("files_id", 1).append("n", 1); if (!hasIndex(clientSession, chunksCollection.withReadPreference(primary()), chunksIndex)) { createIndex(clientSession, chunksCollection, chunksIndex, new IndexOptions().unique(true)); } } checkedIndexes = true; } }
private void checkCreateIndex(@Nullable final ClientSession clientSession) { if (!checkedIndexes) { if (collectionIsEmpty(clientSession, filesCollection.withDocumentClass(Document.class).withReadPreference(primary()))) { Document filesIndex = new Document("filename", 1).append("uploadDate", 1); if (!hasIndex(clientSession, filesCollection.withReadPreference(primary()), filesIndex)) { createIndex(clientSession, filesCollection, filesIndex, new IndexOptions()); } Document chunksIndex = new Document("files_id", 1).append("n", 1); if (!hasIndex(clientSession, chunksCollection.withReadPreference(primary()), chunksIndex)) { createIndex(clientSession, chunksCollection, chunksIndex, new IndexOptions().unique(true)); } } checkedIndexes = true; } }
private void checkCreateIndex(@Nullable final ClientSession clientSession) { if (!checkedIndexes) { if (collectionIsEmpty(clientSession, filesCollection.withDocumentClass(Document.class).withReadPreference(primary()))) { Document filesIndex = new Document("filename", 1).append("uploadDate", 1); if (!hasIndex(clientSession, filesCollection.withReadPreference(primary()), filesIndex)) { createIndex(clientSession, filesCollection, filesIndex, new IndexOptions()); } Document chunksIndex = new Document("files_id", 1).append("n", 1); if (!hasIndex(clientSession, chunksCollection.withReadPreference(primary()), chunksIndex)) { createIndex(clientSession, chunksCollection, chunksIndex, new IndexOptions().unique(true)); } } checkedIndexes = true; } }