Hello Everyone, For the below mentioned document, tagSerialNumbers array with string values. Now i want to update the same from datatype String to Int64. Please help in updating the data type.
db.RetailerRequest.updateMany
(
{"fulfill.tagSerialNumbers":{$type:"string"}},
[
{$set:
{fulfill:
{$map:
{input:"$fulfill",
in:{$mergeObjects:
["$this",{tagSerialNumbers:
{ $toLong: "$$this"}}]}}}
}
}
]
)
Now i am getting the error: MongoServerError: Unsupported conversion from object to long in $convert with no onError value
Please let me know how to proceed further
If you look at the $map documentation you will read the following about $$this:
A name for the variable that represents each individual element of the input array. If no name is specified, the variable name defaults to this.
In you sample document, the field fulfill is an array of objects. You $map using input:$fulfill and $toLong:$$this.tagSerialNumbers, but tagSerialNumbers is an array and this is why you get: