janhoedt
asked on
Powershell MongoDB: Get-MdbcData : Cannot bind parameter 'Collection' to the target. Exception setting "Collection"
Hi,
Please see https://www.experts-exchange.com/questions/29154913/Powershell-and-jsons-to-a-Mongodb-PS-management-mongodb-itemd.html
I seem to be able to connect to my db, but I can't see if I am connected. Database and collection exist, I can see this via MongoDB gui.
Got error below. Please advise.
$MongoDbServer = 'Myserver:27017
#$Port = '27017'
$DatabaseName = 'TestDB'
$CollectionName = 'TestCollection'
$ConnectionString = "mongodb://$MongoDb/$Datab asename"
Connect-Mdbc -ConnectionString $ConnectionString -DatabaseName $DatabaseName -CollectionName $CollectionName
#No error here
Get-MdbcData -Collection $CollectionName
#Then the error
Get-MdbcData : Cannot bind parameter 'Collection' to the target. Exception setting "Collection": "Unexpected type of parameter or variable Collection."
At line:1 char:26
+ Get-MdbcData -Collection $CollectionName
Please see https://www.experts-exchange.com/questions/29154913/Powershell-and-jsons-to-a-Mongodb-PS-management-mongodb-itemd.html
I seem to be able to connect to my db, but I can't see if I am connected. Database and collection exist, I can see this via MongoDB gui.
Got error below. Please advise.
$MongoDbServer = 'Myserver:27017
#$Port = '27017'
$DatabaseName = 'TestDB'
$CollectionName = 'TestCollection'
$ConnectionString = "mongodb://$MongoDb/$Datab
Connect-Mdbc -ConnectionString $ConnectionString -DatabaseName $DatabaseName -CollectionName $CollectionName
#No error here
Get-MdbcData -Collection $CollectionName
#Then the error
Get-MdbcData : Cannot bind parameter 'Collection' to the target. Exception setting "Collection": "Unexpected type of parameter or variable Collection."
At line:1 char:26
+ Get-MdbcData -Collection $CollectionName
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, as I said, I'm not using MongoDb myself, so I can only help with the PowerShell based part.
ASKER
Found the https://github.com/oze4/PsMongo which apparently enables to write jsons to mongodb.
Setup works, but can't add jsons
Add-JsonDocumentIntoMongoC ollection -JsonData $jsonData -MongoConnection $MongoConnection -CollectionName $Collection
Error is Something went wrong saving document to database '' in collection ''! Full Error: Exception calling "JSONtoBSON" with "1" argument(s): "Cannot deserialize a 'BsonDocument' from BsonType 'Array'."
Setup works, but can't add jsons
Add-JsonDocumentIntoMongoC
Error is Something went wrong saving document to database '' in collection ''! Full Error: Exception calling "JSONtoBSON" with "1" argument(s): "Cannot deserialize a 'BsonDocument' from BsonType 'Array'."
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, will try that!
How ever, each json I import should be added as one entry. Each json contain all info on a specific software (vendor, Name, version). Is this way of import then a good approach?
How ever, each json I import should be added as one entry. Each json contain all info on a specific software (vendor, Name, version). Is this way of import then a good approach?
Can't really tell you if it's a good approach, but that approach will only import one PS json object at a time.
ASKER
First one failed, also 2nd command, error is:
'Something went wrong saving document to database '' in collection ''! Full Error: Exception calling "JSONtoBSON" with "1" argument(s): "Cannot deserialize a 'BsonDocument' from BsonType 'Array'."'
'Something went wrong saving document to database '' in collection ''! Full Error: Exception calling "JSONtoBSON" with "1" argument(s): "Cannot deserialize a 'BsonDocument' from BsonType 'Array'."'
Then I guess that your input json contains an array that Add-JsonDocumentIntoMongoC ollection can't handle.
This is straying too far from the original (resolved) question, into plain MongoDB territory, where I can't be of any real help, I'm afraid.
This is straying too far from the original (resolved) question, into plain MongoDB territory, where I can't be of any real help, I'm afraid.
ASKER
➜ $Collection
Database FullName Name Settings
-------- -------- ---- --------
TestDB TesttDB ...
But the Get-MdbcData -Collection $Collection doesn't give any data
Added some sample data, but that's an object id. I have some jsons for a specific task, how do I add them, so I can check if I can query them?
F.e. I have jsons for software intake process, jsons for configs, jsons for software processing etc