Skip to content

Commit

Permalink
Merge pull request #300 from Cognifide/create_mongo_db_indexes_in_code
Browse files Browse the repository at this point in the history
Creating indexes for collection automatically
  • Loading branch information
tkaik authored Aug 6, 2018
2 parents ee97087 + 0784ab1 commit 3800206
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to AET will be documented in this file.
## Unreleased
**List of changes that are finished but not yet released in any final version.**

- [PR-300](https://github.com/Cognifide/aet/pull/300) Added creating indexes for collection
- [PR-289](https://github.com/Cognifide/aet/pull/289) User now stays on the same tab while navigating between URLs
- [PR-271](https://github.com/Cognifide/aet/pull/271) Added possibility to override name parameter from the aet client
- [PR-268](https://github.com/Cognifide/aet/pull/268) Bobcat upgrade to version 1.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.mongodb.DB;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import java.net.UnknownHostException;
import java.util.ArrayList;
Expand All @@ -33,6 +34,9 @@
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.bson.BsonDocument;
import org.bson.BsonInt32;
import org.bson.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -199,6 +203,15 @@ public MongoDatabase getDatabase(String dbName, Boolean autoCreate) {
} else if (allowAutoCreate && autoCreate) {
database = mongoClient.getDatabase(lowerCaseDbName);
database.createCollection(MetadataDAOMongoDBImpl.METADATA_COLLECTION_NAME);
MongoCollection<Document> collection = database
.getCollection(MetadataDAOMongoDBImpl.METADATA_COLLECTION_NAME);
collection.createIndex(new BsonDocument().append("version", new BsonInt32(-1)));
collection.createIndex(new BsonDocument()
.append("correlationId", new BsonInt32(1))
.append("version", new BsonInt32(-1)));
collection.createIndex(new BsonDocument()
.append("name", new BsonInt32(1))
.append("version", new BsonInt32(-1)));
}
return database;
}
Expand Down

0 comments on commit 3800206

Please sign in to comment.