Skip to content

Commit

Permalink
create indexes
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy committed Aug 8, 2024
1 parent 852c9b5 commit 9425d75
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import java.util.stream.StreamSupport;

import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.Indexes;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.result.UpdateResult;
Expand Down Expand Up @@ -525,6 +528,7 @@ public void doStore(String id, SessionData data, long lastSaveTime) throws Excep

protected void ensureIndexes() throws MongoException
{

// FIXME
// _version1 = new BasicDBObject(getContextSubfield(__VERSION), 1);
// DBObject idKey = BasicDBObjectBuilder.start().add("id", 1).get();
Expand All @@ -535,17 +539,23 @@ protected void ensureIndexes() throws MongoException
// .add("sparse", false)
// .add("unique", true)
// .get());
//

String createResult = _dbSessions.createIndex(Indexes.text("id"), new IndexOptions().unique(true).name("id_1").sparse(false));

// DBObject versionKey = BasicDBObjectBuilder.start().add("id", 1).add("version", 1).get();
// _dbSessions.createIndex(versionKey, BasicDBObjectBuilder.start()
// .add("name", "id_1_version_1")
// .add("ns", _dbSessions.getFullName())
// .add("sparse", false)
// .add("unique", true)
// .get());
// if (LOG.isDebugEnabled())
// LOG.debug("Done ensure Mongodb indexes existing");
// //TODO perhaps index on expiry time?

createResult = _dbSessions.createIndex(Indexes.compoundIndex(Indexes.text("id"), Indexes.text("version")),
new IndexOptions().unique(true).name("id_1_version_1").sparse(false));

if (LOG.isDebugEnabled())
LOG.debug("Done ensure Mongodb indexes existing");
//TODO perhaps index on expiry time?
}

private String getContextField()
Expand Down

0 comments on commit 9425d75

Please sign in to comment.