MongoDB c#创建角色?
我正在尝试与c#driver一起创建一个角色。 谁能告诉我怎么做 我试过几种类似的方法:MongoDB c#创建角色?,c#,mongodb,C#,Mongodb,我正在尝试与c#driver一起创建一个角色。 谁能告诉我怎么做 我试过几种类似的方法: var command = new CommandDocument( new BsonDocument { { "createRole", "Testentity_read" }, { "privileges", new BsonArray(new BsonDoc
var command = new CommandDocument(
new BsonDocument
{
{ "createRole", "Testentity_read" },
{ "privileges", new BsonArray(new BsonDocument
{
{
"resource", new BsonDocument
{
{"db", "MyDb"},
{"collection", "Testentity"}
}
},
{
"actions", new BsonArray {"read"}
}
})},
{ "roles", new BsonArray()}
}
);
var result = _database.RunCommand(command);
但总是有这样的例外:
".NET type MongoDB.Bson.BsonElement cannot be mapped to a BsonValue."
我发现了如何从C#driver创建角色 以下是我尝试做的:
var command = new CommandDocument
{
{
"createRole", "Testentity_find"
},
{
"privileges", new BsonArray
{
new BsonDocument
{
{
"resource", new BsonDocument
{
{"db", "MyDb"},
{"collection", "Testentity"}
}
},
{
"actions", new BsonArray {"find"}
}
}
}
},
{ "roles", new BsonArray()}
};