my question is very simple, I have:
- Mongodb server running on a Linux server
- Windows machine with powershell
how can I connect my powershell to insert/add/update documents from my Windows (powershell) server to mongodb database instance running on a remote linux server?
I tried using C++ drivers but does not connect.
this is my code:
$mongoDbDriverPath = "C:\scripts\CSharpDriver-1.9-rc0\"; Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Bson.dll" Add-Type -Path "$($mongoDbDriverPath)\MongoDB.Driver.dll" $dbName = "mydb" $collectionName = "backupData" $db = [MongoDB.Driver.MongoDatabase]::Create("mongodb://<username>:<passsword>@<IP>:27017/$($dbName)") $collection = $db[$collectionName] $document = new-object MongoDB.Bson.BsonDocument $document.Add("PreName",[MongoDB.Bson.BsonValue]::Create("Daniel")) $document.Add("LastName",[MongoDB.Bson.BsonValue]::Create("Weber")) $collection.save($document)
This is what I get
Exception calling "Save" with "1" argument(s): "Unable to connect to server <IP>:27017: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond <IP>:27017." At C:\scripts\mongo_test.ps1:14 char:17 + $collection.save <<<< ($document) + CategoryInfo : NotSpecified: (:) , MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
thank you very much