Recursion mongodb: Delete the Parent Directory along with the Children's Catalogs


#1

Hey. How to remove in collections the parent’s catalog with children’s catalogs and with the documents in the children’s catalogs.

I want to delete the partent directory with id: “1” and with it children’s directories id: “2,3” and children’s catalogs of children id: “4”.

{
  '_id': '1',
   'name': 'parent',
  'idCatalog': 'null',
},
{
  '_id': '2',
  'name': 'B',
  'idCatalog': '1',
},
{
  '_id': '3',
  'name': 'C',
  'idCatalog': '1',
},
{
  '_id': '4',
  'name': 'D',
  'idCatalog': '2',
}

— CATALOG PARENT <— I am removing it
-------- CATALOG A
------------- document A1
------------- document A2
-------- CATALOG B
-------- document B1

CATALOG PARTENT {_id:“CATALOG PARTENT”}

– CATALOG A {_id:“KATALOG A”, idCatalog: “CATALOG PARTENT”}

---- document A1 {_id: “document A1”, idCatalog: “CATALOG A” }

---- document A2 {_id: “document A2”, idCatalog: “CATALOG A” }

– CATALOG B {_id:“CATALOG B”, idCatalog: “CATALOG PARTENT”}

---- document B1 {_id:“document B1”, idCatalog: “CATALOG B”}