Closed swedan333 closed 3 years ago
What is the Mdbc version? What is the error? What are you trying to do? It looks like you build a filter but use it as -Options
instead of -Filter
, it's not clear.
This code runs without errors. But I am not sure it does what you need.
$arrayFilters = New-Object System.Collections.Generic.List[MongoDB.Driver.ArrayFilterDefinition]
$filter = [MongoDB.Bson.BsonDocument]::new(@{
'credential.guid' = @{
'$eq' = '8ab9d46a-7af4-46bc-96c3-b98529af1a95'
}
})
[MongoDB.Driver.BsonDocumentArrayFilterDefinition[object]]$credentialId = $filter
$arrayFilters.Add($credentialId)
$mOptions = [MongoDB.Driver.UpdateOptions]::new()
$mOptions.ArrayFilters = $arrayFilters
Update-MdbcData -Filter @{} -Collection $colCompany -Update @{'$addToSet' = @{'credential.$[credential].test' = $dataObj}} -Options $mOptions -Result
Hi, and thanks for the quick response! I'm running Mdbc version 6.5.10 and I am trying to update sub arrays using Arrayfilters, although the code ran without errors it still did not update the record.
Solved! Was the -filter as you suggested, thought I could update multiple. thanks for the proper arrayFilters implementation, maybe this should be documented..
I am glad it's solved!
thanks for the proper arrayFilters implementation, maybe this should be documented..
I do not really know how and what to document in this case. It's just some expected (!) quirks of PowerShell on translating from C#. In a way, some of them can be found in Mdbc tests in the repo.
is there a right way of doing this?