'Create a user in MongoDb using powershell
I'm using MongoDb v3.0.3 and want to create a user in a database with admin privileges using powershell. I hook into the C# driver but I don't get very far:
$pathToMongoDbCSharpDriver = "F:\Work\...\mongocsharpdriver.1.9.2\lib\net35"
Add-Type -Path "$pathToMongoDbCSharpDriver\MongoDB.Bson.dll"
Add-Type -Path "$pathToMongoDbCSharpDriver\MongoDB.Driver.dll"
$client = New-Object -TypeName MongoDB.Driver.MongoClient -ArgumentList "mongodb://localhost:30000"
$server = $client.GetServer()
$databaseName = "Dev"
$collectionName = "Settings"
$database = $server.GetDatabase($databaseName)
$collection = $database.GetCollection($collectionName)
$credentials = New-Object -TypeName MongoDB.Driver.MongoCredential("Admin", "password", $true);
$user = New-Object -TypeName MongoDB.Driver.MongoUser($credentials, $false)
$credentials fails because argument 1 it is not a MongoIdentity and I can't find any information about how to create one of these. Any help would be gratefully received
Solution 1:[1]
I use all the parameters in the argument list. The following works fine for me:
$Client = New-Object -TypeName MongoDB.Driver.MongoClient -ArgumentList "mongodb://dbuser:dbpass@localhost:27017/test"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jan Rothkegel |