I’ve tryed running a raw mongo command from C# this is the command that I’m interested to run in C#
db.getUser("MyUser")
I’ve tried
public static async Task GetUserInfoAsync(this IMongoDatabase database, string username, string databaseName)
{
try
{
BsonDocument document = new BsonDocument
{
{"usersInfo", new BsonDocument
{
{ "user", username},
{ "db", databaseName}
}
}
};
BsonDocumentCommand<BsonDocument> command = new BsonDocumentCommand<BsonDocument>(document);
var t = await database.RunCommandAsync(command);
}
catch (Exception ex)
{
throw;
}
}
What I get is
ok=1 , users = []
no matter if the users exists or not
2
Answers
Check what you expect to see in the shell, for now it looks like the filter data (about
db
?) you provide is incorrect. Do you see any result withoutdb
filter? See for details. There is no special logic from .net driver here, all what it does is fully the same asdb.getUsers
does in the shell. You may see it in the shell source code:You can try this code which uses the command usersInfo.