Suppose I have a collection in mongoDB like given below -
{
name : "Abhishek",
Roll_no : null,
hobby : stackoverflow
},
{
name : null,
Roll_no : 1,
hobby : null
}
Now I want to delete the fields in my Documents where the field values are null. I know that I can do it using the $unset in following way -
db.collection.updateMany({name: null}, { $unset : { name : 1 }});
And we could do it in the same way for hobby and name field.
But I was wondering if I can do the same deletion operation using just one query? I was wondering if maybe I could use $or or something else to achieve the same effect but in a single command.
Any ideas?