[CSHARP-1712] accessing mongodb v3.x with powershell Created: 18/Jul/16  Updated: 05/Apr/19  Resolved: 18/Jul/16

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

Type: Task Priority: Major - P3
Reporter: Ross Jurek Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: mongodb, powershell, question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongodb v3 running on redhat, powershell 4.0 running on windows 2012 R2


Issue Links:
Duplicate
duplicates CSHARP-1713 Need Powershell to access mongodb v3.x Closed

 Description   

I had a powershell script that was accessing mongodb v2.x and after the upgrade to mongodb 3.x the script is failing to connect to the database, the error is that credentials are wrong. I have upgraded to the latest version of the csharp mongo driver, but still can not connect to the db. I am looking for the specific driver and connection string for powershell to connect to mongodb v3.



 Comments   
Comment by Ross Jurek [ 18/Jul/16 ]
          • driver 1.7 from 10gen, mongo 2.6 - This code gives a credential error when changing to the 3.2.1 mongodb use old driver, changed to new driver, error that create method does not exist.
            $mongoDbDriverPath = "C:\utilities\mongoDB_1\"
            $dbName = "Prod"
            $collectionName = "Collect"
            Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Driver.dll"
            Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Driver.Core.dll"
            Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Bson.dll"
            $db = [MongoDB.Driver.MongoDatabase]::Create("mongodb://user:password@server/$($dbname)")
            $collection = $db[$collectionName]
            $query = [MongoDB.Driver.Builders.Query]::AND(
            [MongoDB.Driver.Builders.Query]::EQ("Result","Response status code does not indicate success: 403 (Forbidden)."),
            [MongoDB.Driver.Builders.Query]::EQ("ItemName","Automatic but Stopped Services"))
            $results = $collection.find($query)
          • 2.6 csharpdriver, mongodb 3.2.1 - get Cannot find an overload for "GetCollection" and the argument count: "1".

$mongoDbDriverPath = "C:\utilities\mongoDB_2\"
$dbName = "Prod"
$collectionName = "Collect"
Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Driver.dll"
Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Driver.Core.dll"
Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Bson.dll"
Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Driver.GridFS.dll"
Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Driver.Legacy.dll"
$client = New-Object -TypeName MongoDB.Driver.MongoClient -ArgumentList "mongodb://user:password@server"

$database = $client.GetDatabase($dbName)
$collection = $database.GetCollection('collect')

$query = [MongoDB.Driver.Builders.Query]::AND(
[MongoDB.Driver.Builders.Query]::EQ("Result","Response status code does not indicate success: 403 (Forbidden)."),
[MongoDB.Driver.Builders.Query]::EQ("ItemName","KO - Automatic but Stopped Services"))

$results = $collection.find($query)

Comment by Emily Stolfo [ 18/Jul/16 ]

Hi rjurek

I hope you don't mind that I moved your question to the CSHARP project. You originally created the ticket in the MONGOID project, which seems like it was a mistake, as Mongoid is the Ruby ODM.

Thanks
Emily

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