[CSHARP-1866] GridFS should check whether indexes already exist before trying to create them Created: 13/Dec/16  Updated: 22/Apr/17  Resolved: 27/Dec/16

Status: Closed
Project: C# Driver
Component/s: GridFS
Affects Version/s: 2.1
Fix Version/s: 2.4.1

Type: Bug Priority: Major - P3
Reporter: Tomak Ksenia Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: GridFS, Permissions
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

.NET


Issue Links:
Duplicate
is duplicated by CSHARP-1788 Manage Index on GridFS Closed
Backwards Compatibility: Fully Compatible

 Description   

In our application we have some security restrictions for user which uses GridFS.
User granted actions are: "insert", "remove", "update", "find".
We don't want to grant database management actions, such as "createIndex", to application user.
In our situation OpenUploadStream method in GridFSBucket class try to create index for GridFS collection (because collection is empty) and fails with MongoCommandException "not authorized on DBNAME to execute command { createIndexes: "COLLECTIONNAME.files"...".
I can send pull request with checking if index already exists to avoid index creation.
But it is fundamentally wrong to do DBA's work from driver.
DBA should create all necessary indexes from deployment script.



 Comments   
Comment by Githook User [ 27/Dec/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1866: GridFS should check whether the indexes already exist before trying to create them.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/54b263d86da003266adf45496d4192ac1d37f593

Comment by Robert Stam [ 22/Dec/16 ]

I agree with you that applications normally shouldn't do DBA like functions automatically.

However, in the case of GridFS the decision was made that most users would treat GridFS like a black box and wouldn't even know that certain indexes need to be created to support GridFS, so drivers create these indexes automatically.

The GridFS spec says that drivers should only create the indexes if the collection is empty and the index does not already exist.

The .NET driver has a bug in that it is only checking whether the collection is empty It should also check whether the index already exists.

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