Prats
Prats

Reputation: 1765

Delete the mongo records

I have a mongo db design like a parent process and its subprocesses, I have only one level of relationship in mongo and I need to delete all the processes when the parent process is deleted.

{
        "documentId" : ObjectId("510bb7eabc6f30f807043242318"),
        "processId" : 2206755353999,
        "parentProcessId" : null,
}

{
        "documentId" : ObjectId("510bba1f88c172f4153252301d"),
        "processId" : 2206755357078,
        "parentProcessId" : 2206755353999,
}

{
        "documentId" : ObjectId("510bba1f88c172f415005435435d"),
        "processId" : 2206755356068,
        "parentProcessId" : 2206755357078,
}

I wanted to delete the entire above documents while deleting the first process id "processId" : 2206755353999

I am using node.js, mongooose and mongo. Any thoughts please ?

Upvotes: 1

Views: 190

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230306

There is no "cascade delete", especially for your custom tree structure. You have to delete all children yourself (hint: first discover children, then start deleting records)

Upvotes: 3

Related Questions