Reputation: 55
I have the following documents
{ _id:"myId", balance:1 }
and I want to change the field in number type to an array with the same number.
{ _id:"myId", balance: [1], }
tried
Collection.updateMany({ balance: { $type: 'number' } }, { $set: { balance: ["$balance"] } });
, didn't work ($balance string). How can i do this?
Upvotes: 1
Views: 85
Reputation: 20334
You have to wrap the update config with []
since you are using aggregation framework to update:
db.collection.update({
balance: {
$type: "number"
}
},
[
{
$set: {
balance: [
"$balance"
]
}
}
])
Upvotes: 1