[CSHARP-1722] Command aggregate failed: not authorized on DB to execute command Created: 22/Jul/16  Updated: 05/Apr/19  Resolved: 22/Jul/16

Status: Closed
Project: C# Driver
Component/s: Security
Affects Version/s: 2.2.4
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Marko Hrovatic Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver, question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows



 Description   

Doing

_db.GetCollection<TEntity>(typeof(TEntity).Name).AsQueryable().Count()

results in

Command aggregate failed: not authorized on DB to execute command { aggregate: "Customer", pipeline: [ { $sort:

{ lastname: 1, companyShortTitle: 1 }

}, { $group: { _id: 1, __result:

{ $sum: 1 }

} } ], cursor: {} }.

The user that uses the conncection has dbAdmin, dbOwner and readWrite roles.



 Comments   
Comment by Marko Hrovatic [ 22/Jul/16 ]

You are right. I just debugged my code. The issue was with IoC/DI. In some cases the Credentials on MongoClient are empty, don't know why but I will figure it out. This was hard to figure out because it manifested only within one controller action.

You can close this for now.

Comment by Craig Wilson [ 22/Jul/16 ]

Connections are authenticated when they are opened, so if it works in one place and not the other, it's gonna have to be a permissions thing.

Are you sure that typeof(TEntity).Name is the correct collection name? Is TEntity polymorphic and not actually what you are expecting?

Comment by Marko Hrovatic [ 22/Jul/16 ]

1. Not at this collection but can at others in the same DB with the same user.

2. Haven't tried.

Comment by Craig Wilson [ 22/Jul/16 ]

1. Can you issue other queries? Using find or count? Can you insert/update/remove?

2. Are you able to authenticate with the shell and execute these commands?

Comment by Marko Hrovatic [ 22/Jul/16 ]

This only happens when Authorization is enabled in MongoDb (with mongod -auth). Otherwise the Count runs fine.

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