1

Let's say I have some data in a database that looks like this.

person = {
  id: 0,
  name: 'Kyle',
  children: [23, 18, 7]
};

child = {
  id: 23,
  name: 'Colin'
}

If the child is deleted what is the best practice to remove the id reference from the person? Mainly trying to figure out a re-usable way to prune data on the fly without writing a large amount of code.

Community
  • 1
  • 1
Ash Blue
  • 5,344
  • 5
  • 30
  • 36
  • 1
    Then "embed" the data rather than use another collection. Which should have been your primary reason for choosing MongoDB. This really is far to minimal a case to have any meaning to you or others beyond this small data sample. If you believe you have another case you should express it explicitly. – Neil Lunn Jun 17 '14 at 12:29
  • 2
    One possibility is to use Mongoose middleware to do this: http://stackoverflow.com/a/14349259/1259510 – JohnnyHK Jun 18 '14 at 16:16

0 Answers0