0

I'm using mongodb and waterline to try to delete something a node from my collection and it doesn't work

User.find({}).done(function(err, myObjects){
  console.log(myObjects[0].id)
})

"myId"

User.find({}).done(function(err, myObjects){
  User.findOne({id: myObjects[0].id}).done(function(err, myObject){
    console.log(myObject);
  });
});
undefined

Realistically I want to just destroy everything in the database, but every time I try to it just sticks around, I'm considering trying postgres, but I understood that mongo could be useful for my application. Maybe I just don't understand how waterline works also.

Carson Wright
  • 323
  • 3
  • 12
  • I don't see in your code where you're trying to delete something. You need to call `User.destroy` to delete multiple instances, or call the `destroy` method of an instance to destroy that specific object. – sgress454 May 09 '14 at 21:47
  • I think .done() was deprecated, try using .exec() instead – Kory May 10 '14 at 15:37
  • Yeah Scott I was getting to that, I couldn't even find the object to destroy, I wanted to do myObject.destroy() but I couldn't even find the object. I now go into my mongo db and manually delete the things I need to delete. But as long as everything looks right up there other than moving the done function I'll continue and figure it out later. – Carson Wright May 12 '14 at 05:16
  • 1
    Ok, but my point is that you don't need to find the object beforehand. Just do `User.destroy({id: myObjects[0].id}).exec(...)`. – sgress454 May 13 '14 at 16:01
  • Ah, interesting, thank you – Carson Wright May 13 '14 at 21:40

0 Answers0