Permalink
Browse files

MongeezDao: add support for MongoDB 2.4

MongoDB used to support treating arbitrary values in an index definition as "include this field in the index".
As of 2.4, it no longer does.  We were using this (albeit unintentionally) in our indexes for changeset executions.
This change makes it so that the indexes can be correctly created on MongoDB 2.4.
It also drops any of the old no-longer-supported indexes so that they stop producing warning messages.

http://docs.mongodb.org/manual/release-notes/2.4-index-types/
  • Loading branch information...
1 parent 01128b8 commit 77f199b44fafd484cbaf926eea8b2753266aa803 David M. Carr committed Mar 20, 2013
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/main/java/org/mongeez/dao/MongeezDao.java
View
16 src/main/java/org/mongeez/dao/MongeezDao.java
@@ -46,6 +46,7 @@ public MongeezDao(Mongo mongo, String databaseName, MongoAuth auth) {
private void configure() {
addTypeToUntypedRecords();
loadConfigurationRecord();
+ dropObsoleteChangeSetExecutionIndices();
ensureChangeSetExecutionIndex();
}
@@ -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);
}

0 comments on commit 77f199b

Please sign in to comment.