New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add-MdbcData only adds 1 document at a time #51
Comments
FWIW, many PowerShell official and community cmdlets do not follow this "practice". Try Out-String -InputObject @(@{x=1}, @{x=2})
@(@{x=1}, @{x=2}) | Out-String PowerShell common practice is using the pipeline for many input objects. |
Writing one at a time is quite slow so a bulk insert option would be quite handy. I also explored trying to call db.collection.bulkWrite() using Invoke-MdbcCommand but it doesn't appear that shell methods can be called via that cmdlet (an Invoke-MdbcShellCommand cmdlet would be awesome to have). |
@lesterw1 Does this all exist in C# driver? Mdbc does not use shell, it uses C# driver. The examples/suggestions in shell format are not that useful... |
Done, v6.5.8 |
Just tested v6.5.8. Using a collection for -InputObject is about 8% faster than pipelining. Great result! Thank you. |
What about using the C# driver collection.BulkWriteAsync() as a further optimization? |
Unlike this topic suggestion, |
The Add-MdbcData cmdlet only adds one document at a time when the -InputObject switch is used with an array. For example:
Add-MdbcData -InputObject $MyArray -Collection $coll
, my $MyArray contains an array of documents. Passing an array this way simply adds a single document containing an array of the documents -- not exactly as intended.However, using the PowerShell piping iterator
$MyArray | Add-MdbcData -Collection $coll
does work.This behaviour differs from PowerShell practice to also allow the set of objects to be passed and iterated by the implementation (possibly using db.collection.bulkWrite() ?). At minimum, the documentation page should be updated to reflex this behaviour. Ideally though, passing in an array could be detected by the underlying code (which is faster than using the PowerShell piping iterator).
The text was updated successfully, but these errors were encountered: