Skip to content

Commit

Permalink
Merge pull request mongeez#25 from davidmc24/2.4-compatibility
Browse files Browse the repository at this point in the history
MongeezDao: add support for MongoDB 2.4
  • Loading branch information
epishkin committed Mar 20, 2013
2 parents 01128b8 + 77f199b commit 219b7a5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/org/mongeez/dao/MongeezDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public MongeezDao(Mongo mongo, String databaseName, MongoAuth auth) {
private void configure() {
addTypeToUntypedRecords();
loadConfigurationRecord();
dropObsoleteChangeSetExecutionIndices();
ensureChangeSetExecutionIndex();
}

Expand Down Expand Up @@ -84,9 +85,22 @@ private void loadConfigurationRecord() {
}
}

/**
* Removes indices that were generated by versions before 0.9.3, since they're not supported by MongoDB 2.4+
*/
private void dropObsoleteChangeSetExecutionIndices() {
String indexName = "type_changeSetExecution_file_1_changeId_1_author_1_resourcePath_1";
DBCollection collection = getMongeezCollection();
for (DBObject dbObject : collection.getIndexInfo()) {
if (indexName.equals(dbObject.get("name"))) {
collection.dropIndex(indexName);
}
}
}

private void ensureChangeSetExecutionIndex() {
BasicDBObject keys = new BasicDBObject();
keys.append("type", RecordType.changeSetExecution.name());
keys.append("type", 1);
for (ChangeSetAttribute attribute : changeSetAttributes) {
keys.append(attribute.name(), 1);
}
Expand Down

0 comments on commit 219b7a5

Please sign in to comment.