I am wanting to rename a property in one of our MongoDB collections because it was pluralized where it should be singular. However, when I try this in the Mongo shell:
db.getCollection("customers").updateMany( { _id: {$exists: true} }, { $rename: { "billingOptions.0.paymentCards": "billingOptions.0.paymentCard" } } )
... I get this "cannot be an array element" error:
"errmsg" : "The source field cannot be an array element, 'billingOptions.0.paymentCards' in doc with _id: ObjectId('3d12fefc093r76146ccf50g8') has an array field called 'billingOptions'"
Not sure why this would be a problem, since I'm telling it precisely which array element to target. But, either way, this being the case, what operation can I use to rename this property
Here's an example of the relevant section of the document as it is now:
"billingOptions" : [
{
"method" : "private",
"paymentCards": {
"deleted" : false,
// other props
}
},
]
And this is what I'd like it to look like after:
"billingOptions" : [
{
"method" : "private",
"paymentCard": {
"deleted" : false,
// other props
}
},
]
Note that "billingOptions" is a property on the root of the document. All I want to do is rename all instances of "paymentCards" to "paymentCard", since it is a singular object here, rather than an array.
paymentCardsonly from first billingOption (index0) or from all of them ? Could you share a sample document and expected updated doc ?