0

I have defined different roles, one of them allow the specific user to read only one collection. There are many different collections but only one can be readen for this user.

Now when he connects, I want to list all collections he can read.

In C# with mongo driver there is a possibility to list the collections, but the function return an error if the rights to read are wrong.

this is where i am blocked into the code:

  var database = client.GetDatabase(DatabaseName);
  foreach (BsonDocument namecollection in database.ListCollectionsAsync().Result.ToListAsync<BsonDocument>().Result)
            {
                string name = namecollection["name"].AsString;
                allcollectionNames.Add(name);
            }

with the shell I founded a function

use someDbName
db.getCollectionInfos( { authorizedCollections : true } )
Magus
  • 57
  • 7
  • Why are you referencing amazon docs? – D. SM Dec 02 '20 at 13:31
  • It is based on MongoDB... I have founded an article about it. Don't ask me where I didn't remember – Magus Dec 02 '20 at 13:34
  • If you are asking about some database other than MongoDB please tag the question accordingly. – D. SM Dec 02 '20 at 13:36
  • I only use MongoDB, I tried another documentations based on mongoDB hoping to find the right informations . But I didn't. So I need still need Help. – Magus Dec 02 '20 at 13:53
  • If your question is about MongoDB you should be referencing MongoDB documentation (which covers all functionality that the server provides). And you should clearly state what your question is. – D. SM Dec 03 '20 at 01:58
  • I have changed the question, it is more precise. – Magus Dec 03 '20 at 09:45
  • OK, so check the documentation of ListCollectionsAsync for correct usage. – D. SM Dec 03 '20 at 15:09
  • You pushed me a lot into the Documentation, I have two list and for one i defined a Role with a control acces onto the collection like here (https://dzone.com/articles/mongodb-tips-tricks-collection-level-access-contro) . Functions like getCollectionInfo or the ListCollections block onto the authorization access when the user connects. What is strange when I am looking at the documentation "If a user does not have required access and runs show collections, MongoDB uses the authenticatedUserPrivileges field returned by connectionStatus to return an approximate list of collections for the user." – Magus Dec 04 '20 at 13:54

1 Answers1

1

According to .net driver documentation (https://api.mongodb.com/csharp/current/html/M_MongoDB_Driver_IMongoDatabase_ListCollectionsAsync.htm, https://api.mongodb.com/csharp/current/html/T_MongoDB_Driver_ListCollectionsOptions.htm) the only option supported presently is the filter. I do not see anything in the driver source that appears relevant to the authorizedCollections option either.

You may consider requesting this functionality via https://jira.mongodb.org/browse/csharp.

D. SM
  • 13,584
  • 3
  • 12
  • 21