[JAVA-3409] GridFS indexes do not created when database is restored with --noIndexRestore Created: 28/Aug/19  Updated: 27/Oct/23  Resolved: 13/Sep/19

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 3.11.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Phillip Wirth Assignee: Ross Lawley
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When restoring a database with {{ --noIndexRestore}} the gridfs indexes, named here do not get created again IF there are already files in grid fs.

Expected:

the indexes get created.

the current code from the 3.11.0 driver is:

 
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;
 }
}

 



 Comments   
Comment by Ross Lawley [ 13/Sep/19 ]

Hi pwirth,

Thanks for the ticket. This behavior is as specified in the GridFS Spec. The indexes are only created on writing to GridFS if the files collection is empty.

In your scenario you would have to manually recreate the indexes to ensure they exist.

Ross

Generated at Thu Feb 08 08:59:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.