Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please update to use db.model instead of mongoose.model #58

Closed
daskyrk opened this issue Apr 12, 2019 · 1 comment
Closed

please update to use db.model instead of mongoose.model #58

daskyrk opened this issue Apr 12, 2019 · 1 comment

Comments

@daskyrk
Copy link

daskyrk commented Apr 12, 2019

I'm submitting a...


[ ] Regression 
[x] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Some times the db command is hanging and returned promise will never resolve. It seems that we should use createConnection with db.model(...) and connect with mongoose.model(...).When i change to use connect, everything works fine, So maybe this plugin should update to prevent this case. please see: https://stackoverflow.com/questions/22786374/queries-hang-when-using-mongoose-createconnection-vs-mongoose-connect

Expected behavior

db command not hang

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

it maybe difficult to reproduce my case, there is some log output:

  public create(docs: Partial<T>): Promise<T> {
    console.log('inner create: start');
    const pro = this._model.create(docs);
    console.log('inner create: end', pro);
    return pro;
  }

  public async createComment(data: CommentDto, req: Request) {
    console.log('create comment service:');
    const comment = await super.create(data);
    console.log('create comment service after:', comment);
}

// log: 
create comment service:
inner create: start
inner create: end Promise { <pending> } // hang there 
catch error in timeout interceptor:

Environment


Nest version: "@nestjs/core": "^6.0.4"
plugin version:  "@nestjs/mongoose": "^6.0.0"



For Tooling issues:
- Node version: v10.15.3  
- Platform:  Mac 

Others:

@kamilmysliwiec
Copy link
Member

It seems that we should use createConnection with db.model(...)

Actually, we are using db.model:

useFactory: (connection: Connection) =>
      connection.model(model.name, model.schema, model.collection),

https://github.com/nestjs/mongoose/blob/master/lib/mongoose.providers.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants