[mongodb] How to Query if pid Value Is Equal to _id Field?

  mongodb, question

The data format is as follows:

/* subset */
 {
 "_id" : ObjectId("5c1f795fbb0eb4399f554e08"),
 "pid": objectid ("5c10cf1acd6ff5730f265a8a")//parent _id
 "knowledge": "sub-knowledge"
 },
 
 /* Parent */
 {
 "_id" : ObjectId("5c10cf1acd6ff5730f265a8a"),
 "knowledge": "parent knowledge"
 },

I want to query all the parents first and return onehasChildField, if there is a subsetpidWith parent set_idEqual, returnstrue, otherwise returnfalse

As above, the results returned by querying the parent set should be as follows:

{
 "_id" : ObjectId("5c10cf1acd6ff5730f265a8a"),
 "know": "Parent Knowledge Point",
 "hasChild": true
 }

Hope to useAggregationThe way to solve, rather than cycle, ask great god advice!

You can refer to$lookup (aggregation)

I hope it will help you.