0

I'm amazed that I can't seem to find a straight answer for this. I SIMPLY want to delete a document from a collection (like deleting a record from a table in mysql). Here is what I have tried:

People.find(
    {key: req.params.key},
    function(err, data) {
        if (err) {
            next(err);
        }
        if (data) {
            data.remove(callback);
        }
    });

function callback() {
    // do something
}

I keep getting this error in the console: "TypeError: Object has no method 'remove'". What am I doing wrong?

Chris Paterson
  • 1,129
  • 5
  • 21
  • 31

1 Answers1

2

I believe this should work for you:

People.remove({ key:req.params.key}, function (err) {});

Or this:

var query = People.remove({ key:req.params.key });
query.exec();

And there are a few other ways to approach this depending upon the nature of your data (is the key unique, do you just want to remove the first one you find, etc).

John Petrone
  • 26,943
  • 6
  • 63
  • 68