Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-205

Add Insert Methods to MongoCollection<TDefaultDocument> for improved powershell support

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.1
    • 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:

      1. 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']);

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            zippy1981 Justin Dearing
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: