-
Type:
Improvement
-
Resolution: Done
-
Priority:
Major - P3
-
Affects Version/s: 1.0
-
Component/s: Feature Request
-
Environment:Powershell
As previously stated powershell cannot call generic methods of non-generic classes without nasty reflection. So Added these insert overloads to MongoCollection<TDefaultDocument> allows us to insert documents.
Powershell script to test:
- We assume that the driver is installed via the MSI.
#[string] $mongoDriverPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\MongoDB CSharpDriver 0.11").'(default)';
[string] $mongoDriverPath = "C:\Program Files (x86)\MongoDB\CSharpDriver 1.0\"
Add-Type -Path "$($mongoDriverPath)\MongoDB.Bson.dll";
[MongoDB.Bson.BsonDocument] $doc = @{
"_id"= [MongoDB.Bson.ObjectId]::GenerateNewId();
"FirstName"= "Justin";
"LastName"= "Dearing";
"PhoneNumbers"= [MongoDB.Bson.BsonDocument] @ { 'Home'= '718-641-2098'; 'Mobile'= '646-288-5621'; };
};
#$doc;
Add-Type -Path "$($mongoDriverPath)\MongoDB.Driver.dll";
$db = [MongoDB.Driver.MongoDatabase]::Create('mongodb://localhost/powershell');
[MongoDB.Driver.MongoCollection[MongoDB.Bson.BsonDocument]] $collection = $db['example1'];
$collection.Insert($doc);
$collection.FindOneById($doc['_id']);