How do I filter out documents from a mongo collection that don't have a sub field, when using aggregation?
The collection looks like this:
{
"_id": ObjectId("adasdasd"),
"obj": { "a": 1 }
},
{
"_id": ObjectId("ergergerg"),
"obj": { "b": 2 }
},
{
"_id": ObjectId("adasdasd"),
"obj": { "a": 3, "b": 4 }
},
How would I use the aggregate() function to only select documents where the "obj" field contains the "b" subfield? The result should look like this:
{
"_id": ObjectId("ergergerg"),
"obj": { "b": 2 }
},
{
"_id": ObjectId("adasdasd"),
"obj": { "a": 3, "b": 4 }
},
I realize that I can use find() and $exists, But I am looking for a solution using aggregate(). Any help is greatly appreciated.