the data format is as follows:
/* */
{
"_id" : ObjectId("5c1f795fbb0eb4399f554e08"),
"pid" : ObjectId("5c10cf1acd6ff5730f265a8a"), //_id
"know" : ""
},
/* */
{
"_id" : ObjectId("5c10cf1acd6ff5730f265a8a"),
"know" : ""
},
I want to query all parents first and return a hasChild
field. If there is a subset pid equal to the parent set _ id , then return true , otherwise return false
as above, the result returned by the query parent set should be as follows:
{
"_id" : ObjectId("5c10cf1acd6ff5730f265a8a"),
"know" : "",
"hasChild": true
}
hope to use Aggregation
to solve the problem, rather than cycle, ask God for advice!