Closed jonatanhost closed 3 years ago
What is your full command with parameters that gives this error?
Just in case, the error is about LastUpdated
but you want to change Updated
. Typo?
That was a typo.
I tried with this command and structure below
Update-MdbcData @{arrayId=1} @{'$set' =@{"array.Updated" = "201212"}}
https://stackoverflow.com/a/30059057/323582
# add test data
Connect-Mdbc -NewCollection
@{_id = ""; array = @( @{ arrayId = "1"; Updated = "201212" }, @{ arrayId = "2"; Updated = "201210" } ) } | Add-MdbcData
# update
Update-MdbcData @{'array.arrayId' = '1'} @{'$set' = @{'array.$.Updated' = "new-value"}}
# { "_id" : "", "array" : [{ "arrayId" : "1", "Updated" : "new-value" }, { "arrayId" : "2", "Updated" : "201210" }] }
(Get-MdbcData).ToString()
I try to update value in a array of a document.
Update-MdbcData : A write operation resulted in an error. Cannot create field 'Updated' in array
The document I have in MongoDB is like below and I want to update value "Updated" for "arrayId" 2.
{ "_id": "", "array": [ { "arrayId": "1", "Updated": "201212" }, { "arrayId": "2", "Updated": "201210" } ] }