jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
287 stars 65 forks source link

gridfs error creating indexes #190

Open fabiofumarola opened 4 years ago

fabiofumarola commented 4 years ago

When I try to connect to a mongodb instance using gridfs I got an error. The error is related to the fact that the client try to create the indexes (files and chunks) while the client is not allowed to do that on the database. These needed collections and the indexes are already created manually. Is there a way to disable the automatic index creating by the client?

jeroen commented 4 years ago

What code did you run? I don't think it will automatically create indexes when you connect?

fabiofumarola commented 4 years ago

Hi Jeron,

thanks for the answer. I have checked the code

https://github.com/jeroen/mongolite/blob/master/R/gridfs.R#L155-L158

#' @useDynLib mongolite R_mongo_gridfs_new
mongo_gridfs_new <- function(client, prefix, db){
  .Call(R_mongo_gridfs_new, client, prefix, db)
}

and the c function called https://github.com/jeroen/mongolite/blob/master/src/mongoc/mongoc-gridfs.c#L131

mongoc_gridfs_t *
_mongoc_gridfs_new (mongoc_client_t *client,
                    const char *db,
                    const char *prefix,
                    bson_error_t *error)
{
....   
   bson_snprintf (buf, sizeof (buf), "%s.files", prefix);
   gridfs->files = mongoc_client_get_collection (client, db, buf);

   **r = _mongoc_gridfs_ensure_index (gridfs, error);**

   if (!r) {
      mongoc_gridfs_destroy (gridfs);
      RETURN (NULL);
   }

   RETURN (gridfs);
}

And it looks like that the indexes are created if not found. Is it correct?

thanks, Fabio

jeroen commented 4 years ago

Yes, this seems to be part of the mongo-c-driver.

@ajdavis is it expected that mongoc_client_get_gridfs always requires permission to create indexes?

ajdavis commented 4 years ago

Hello! I've moved off the mongo-c-driver team, perhaps @kevinAlbs can take a look.

jeroen commented 4 years ago

Oh no, that's so sad! I really enjoyed working with you!

fabiofumarola commented 4 years ago

@kevinAlbs can you please help me?

thanks, Fabio

fabiofumarola commented 4 years ago

if you want I can do a pull request to change the behaviour

jmikola commented 4 years ago

@fabiofumarola: The behavior you're describing where _mongoc_gridfs_new always attempts to create indexes actually does not comply with our GridFS specification. I've opened CDRIVER-3503 to get this addressed and cross-referenced it with this issue. Hopefully it can be scheduled for the forthcoming 1.17 release, as libmongoc's patch policy would not see us address this in a 1.16.x patch release due to it being a longstanding bug.

fabiofumarola commented 4 years ago

@jmikola thanks for the answer. Tell if I can help working on the fix. I'd really like to contribute on it.

jmikola commented 4 years ago

@fabiofumarola: You're welcome to take a shot at creating a pull request. If so, feel free to read up on CDRIVER-3503 and the related issue, CDRIVER-3498, as it probably makes sense to address both at once. The relevant text from the GridFS specification is also linked in CDRIVER-3503.

If you have any questions along the way, I'd suggest you create a JIRA account and continue the conversation on CDRIVER-3503.

fabiofumarola commented 4 years ago

@jmikola thanks

alcaeus commented 4 years ago

After investigating, we've closed CDRIVER-3503 as "Won't do". The API is deprecated and also does not implement the GridFS specification. The mongoc_gridfs_bucket API is an implementation of the specification and only creates indexes when data is being written to the bucket.