Get the Hirearchy View In MongoDB and Spring Boot

Hi @MaBeuLux88_xxx ,

It worked for me as I expected with your immense support. I’ve another requirement under this scenario I’m putting this here hope I can get a good solution from you.

{
    _id: ObjectId("612f84891f2da394c2b8ed21"),
    user: '002',
    refUserId: '001',
    status: 'SUCCESS'
  },
  {
    _id: ObjectId("612f84891f2da394c2b8ed22"),
    user: '003',
    refUserId: '001',
    status: 'SUCCESS'
  },
  {
    _id: ObjectId("612f85a11f2da394c2b8ed23"),
    user: '001',
    status: 'SUCCESS'
  }

This is the previous data set. But when I’m changing it bit like below

{
    _id: ObjectId("612f84891f2da394c2b8ed21"),
    user: '002',
    refUserId: '001',
    status: 'SUCCESS'
  },
  {
    _id: ObjectId("612f84891f2da394c2b8ed22"),
    user: '003',
    refUserId: '002',
    status: 'SUCCESS'
  },
  {
    _id: ObjectId("612f85a11f2da394c2b8ed23"),
    user: '001',
    status: 'SUCCESS'
  }

I’m getting an output like this

001

Here you can Identify this it’s returning the same Objects even after I change the values. Actually it has to be like a below sample example(this is what I expect)

{
  "_id": {
    "$oid": "612f8bccc8188663637695cf"
  },
  "user": "001",
  "status": "SUCCESS"
  "child" : Array
     {
       "_id": {
       "$oid": "612f8bccc8188663637695cd"
       },
      "user": "002",
      "refUserId": "001",
      "status": "SUCCESS"
      "child" : Array
           {
          "_id": {
          "$oid": "612f8bccc8188663637695cd"
          },
          "user": "003",
          "refUserId": "002",
          "status": "SUCCESS"
         }
}

I’ll be grateful if you can help me to solve this problem