These are chat archives for Automattic/mongoose

29th
Jul 2016
Vasiliy Onoprienko
@Regnised
Jul 29 2016 06:30
Hi, who can help me realise task. I want delete some documents and get theirs in callback
db.collection.remove - not return documents =(
Sergei
@osenvosem
Jul 29 2016 07:21

Hi guys! I am trying to add a couple asynchronous pre hooks but the query doesn’t execute after that

  userSchema.pre('find', true, function(next, done) {
    next();
    done();
  });
  userSchema.pre('find', true, function(next, done) {
    next();
    done();
  });

It simply hangs. What can I do wrong here?

Erinç Fırtına
@EricMcRay
Jul 29 2016 08:17
@smirnovshina try without done();
Sergei
@osenvosem
Jul 29 2016 08:20
@EricMcRay i’ve tried. In documentation is written that it is obligatory to execute done() to continue the flow.
Erinç Fırtına
@EricMcRay
Jul 29 2016 08:27
@smirnovshina do you call done function inside a async function, right?
Sergei
@osenvosem
Jul 29 2016 08:28
@EricMcRay right, as I wrote above in example.
Erinç Fırtına
@EricMcRay
Jul 29 2016 08:29
@smirnovshina in your example done and next are sync. Probably, your hooks pass to next hook without call done function
userSchema.pre(‘find’, true, function(next, done){
     setTimeout(function(){
         done();
     }, 100);
     next();
});
I think it should be like this.
Sergei
@osenvosem
Jul 29 2016 08:35
@EricMcRay nope, this doesn’t work.
@EricMcRay and it seems there is no difference between your and my examples. In the documentation written that every async pre hook must execute done() then the method will be executed.
@EricMcRay simply this doesn’t work:
  userSchema.pre('findOne', true, function(next, done) {
    done();
  });
clocked0ne
@clocked0ne
Jul 29 2016 09:15
Does anyone know what the skipInit option actually does when instantiating a Mongoose model?
Still no one knowledgable about this?