[CDRIVER-724] The index ensured by mongoc_client_get_gridfs must be unique Created: 26/Jun/15  Updated: 03/May/17  Resolved: 28/Jun/15

Status: Closed
Project: C Driver
Component/s: GridFS
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Marius Soutier Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to TOOLS-1295 Backport to v2.6 Closed
is related to TOOLS-808 mongofiles creates a different index ... Closed

 Description   

mongoc_client_get_gridfs() returns NULL in MongoDB versions < 3.0.

Error message is:
files_id_1_n_1 already exists with different options

When uploading files (e.g. using mongofiles), MongoDB creates an index with

{unique:1}

in MongoDB 3.0, while it is missing in lower versions.

What is the value of ensuring this index on each access anyway? MongoDB certainly creates the index. This is also a side-effect that should be documented.



 Comments   
Comment by A. Jesse Jiryu Davis [ 29/Jun/15 ]

Yes, sorry about that, you have to delete the non-unique index yourself. Until mongofiles is fixed you should create the unique index, too, to prevent mongofiles from recreating the non-unique index.

Comment by Marius Soutier [ 29/Jun/15 ]

So to summarize - if I'm using mongofiles and I'm using mongoc, I have to delete the faulty index myself? Or is there any other workaround?

Comment by A. Jesse Jiryu Davis [ 28/Jun/15 ]

Thanks. Closing this works as designed, sorry - the upcoming GridFS spec doesn't tell drivers to attempt to replace a wrong index with a right one, and I doubt it would. It's a potentially very expensive operation with unforeseen consequences, should be left up to administrators to decide when to undertake it, not done automatically at unpredictable moment by the driver.

Comment by Marius Soutier [ 28/Jun/15 ]

Done: https://jira.mongodb.org/browse/TOOLS-808

Comment by A. Jesse Jiryu Davis [ 26/Jun/15 ]

Thanks. The "chunks" index should be unique. This may ultimately be a Go driver bug, but meanwhile would you mind opening a ticket here about the inconsistency in mongofiles and MongoDB 3 vs 2.6?:

https://jira.mongodb.org/browse/TOOLS

Comment by Marius Soutier [ 26/Jun/15 ]

It seems that mongofiles (latest version 3.0.4) will create a unique index on MongoDB 3.0, and a non-unique index on MongoDB 2.6.

Comment by A. Jesse Jiryu Davis [ 26/Jun/15 ]

Oh I see, thanks. What about the latest version of mongofiles, does it create a unique index or no?

Comment by Marius Soutier [ 26/Jun/15 ]

The C driver does indeed create the unique index. It's mongofiles that doesn't create the unique index (only a normal index) on earlier MongoDB versions. The driver should not fail but replace the non-unique index (which is my current workaround).

Comment by A. Jesse Jiryu Davis [ 26/Jun/15 ]

Current draft spec for GridFS says: "When a GridFSBucket object is created, drivers MUST ensure that the following indexes exist: a unique index on { files_id : 1, n : 1 } on the chunks collection. If this operation fails because the user is not authorized to create an index, GridFSBucket should recover and continue." What the spec calls a GridFSBucket is the C Driver's mongoc_gridfs_t. So the driver bug is that it creates a non-unique index instead of a unique one.

Drivers are required to ensure certain indexes on the GridFS collections so that standard GridFS operations are performant. The MongoDB server doesn't create those indexes so drivers (and apparently mongofiles 3.0, now that it uses the Go driver).

Comment by A. Jesse Jiryu Davis [ 26/Jun/15 ]

Hi, thanks for the clear report. We're finalizing a specification for how all MongoDB drivers ought to implement GridFS, I'll check with the spec author and see how we want to fix this.

Generated at Wed Feb 07 21:10:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.