Update the key data type from string to int64

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.

{
“_id”: {
“$oid”: “635286ea1c66064140400d3c”
},
“fulfill”: [
{
“itemName”: " ",
“fulfilledQty”: 360,
“fullfilledDate”: “2014-10-15 21:16:42”,
“fulfilledStatus”: {
“statusId”: 3002,
“status”: “RReceivedFull”
},
“retailer”: {
“retailerId”: 10003753,
“name”: “Serco”,
“retailerType”: {
“typeId”: 3002,
“name”: “RegularMasterRetailer”
}
},
“tagSerialNumbers”: [
“137438957072”,
“137438957071”,
“137438957070”,
“137438957069”,
“137438957068”,
“137438957067”,
“137438957066”,
“137438957065”,
“137438957064”,
“137438957063”,
“137438957062”,
“137438957061”,
“137438957060”,
“137438957059”,
“137438957058”,
“137438957057”,
“137438957056”,
“137438957055”,
“137438957054”,
“137438957053”
]
}
]
}

That would be the same process as answered to you in

Hello,

Thanks for your quick response, i tried updating with the below mentioned query:
db.RetailerRequest.updateMany
(
{“fulfill.tagSerialNumbers”:{$type:“string”}},
[
{$set:
{fulfill:
{$map:
{input:"$fulfill",
in:{$mergeObjects:
["$this",{tagSerialNumbers:
{ $toLong: “$$this.tagSerialNumbers”}}]}}}}}] )

But i am getting the below mentioned error:
MongoServerError: Unsupported conversion from array to long in $convert with no onError value

Please help me in updating the query.

The field tagSerialNumbers in the document you shared is an array. That is why you get

You have to $map tagSerialNumbers and convert with { $toLong : $$this }.

Hello, Thanks for quick response. I tried using the below mentioned query:
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

Sorry, but you published exactly the same badly formatted documents and code.

Please

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

Your sample document from the first post is still not formatted in a way we can cut-n-paste.

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:

But I already mentioned:

An hint to the solution was also mentioned: