My collection Looks like this:
[
{
"_id": {
"$oid": "638ecf5247cf747bdd862bfb"
},
"title": "This is title one"
},
{
"_id": {
"$oid": "638ecf5247cf747bdd862bfb"
},
"title": null
},
{
"_id": {
"$oid": "638ecf5247cf747bdd862bfb"
},
"title": "This is title three"
}
]
But I want to convert every title that have null to string (not-found):
[
{
"_id": {
"$oid": "638ecf5247cf747bdd862bfb"
},
"title": "This is title one"
},
{
"_id": {
"$oid": "638ecf5247cf747bdd862bfb"
},
"title": "not-found" // null to be converted to string
},
{
"_id": {
"$oid": "638ecf5247cf747bdd862bfb"
},
"title": "This is title three"
}
]
How to convert null title to string for all documents that have null title?
2
Answers
You can use a simple update:
See how it works on the playground example
3 things:
{title:null}
Playground – https://mongoplayground.net/p/DfAWE1Swszb