Hello,
Let’s start by putting some context to clarify to problem:
We have a first collection named hollywood_stars , for simplicity let’s say it contains only the Star name and the cars which He/She owns.
[{
"_id": "...."
"name": "Matt Damon"
"cars": [
{
"$ref": "car",
"$id": "001"
},
{
"$ref": "car",
"$id": "002"
}]
}
]
The second collection is the car collection, For simplicity, the collection contains cars model with only id and name.
[{
"_id": "001"
"name": "BMW"
},
{
"_id": "002"
"name": "Porsche"
}]
Now, i want to change the name of the car collection from car to cars. So i use the command db.car.renameCollection(“cars”) https://docs.mongodb.com/manual/reference/method/db.collection.renameCollection/
The problem is that the references to cars collection in the hollywood_stars collection still reference the wrong name which is car and therefore the connection is broken.
And my question is : Should i change those references manually ? Or may be there is some command or method that i could use to handle that.
Please Note : In real life example we can find hundreds may be thousands of references of the cars collection in one or multiple other collections (hollywood_stars, sport_stars…).
Best regards.