I want to remove any document that has an empty text string from an object within an object. Is there a way to do this with the MongoDB Aggregation Framework? In this case it will be the text within object_1 and object_2.
"array_of_objects":[{
"city": "Seattle",
"array_1": [],
"object_1":{
"name": "Mandy",
"text" "",
},
"object_2":{
"name": "Billy",
"text" "",
},
}]
If you want to project all the fields that does not have an empty
textstring, use the following query.MongoDB Playground
If you want to to project all the fields that does not have an empty
textstring and empty array, just add a$neempty array check, use the following query:MongoDB Playground
If you want to remove any document that has an empty text string, use an additional $match stage to remove documents with empty text string.
MongoDB Playground