我试图用c#驱动程序创建一个角色。 谁能告诉我怎么做?
我尝试了几样这样的事情:
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."
答案 0 :(得分:0)
我发现了如何使用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()}
};