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

Trying to open unclosed connection. #47

Closed
sholtomaud opened this issue Oct 18, 2017 · 6 comments
Closed

Trying to open unclosed connection. #47

sholtomaud opened this issue Oct 18, 2017 · 6 comments

Comments

@sholtomaud
Copy link

I'm using Mongoose for my server, and when micro-dev restarts it doesn't close the connection nicely so I get an error:

How would I tell micro-dev to close the connection prior to restart?

File changed: src/router/user.js - Restarting server...
{ Error: Trying to open unclosed connection.
    at NativeConnection.Connection._handleOpenArgs (/micro-authentication-starter/node_modules/mongoose/lib/connection.js:214:11)
...
}
@tungv
Copy link
Contributor

tungv commented Oct 18, 2017

You may want to ignore your schema files so it will not reload them.

Assuming you put schema files in <project_dir>/src/models please run micro dev with -i **/src/models. This will neither watch those files nor rerun them

@sholtomaud
Copy link
Author

Thanks for the quick response! :)

I'm afraid that doesn't seem to work, I've tried a few variants, and I have models in the src folder

micro-dev --ignore src/models/*.js index.js 
micro-dev --ignore src/models/ index.js 
micro-dev -i ./src/models index.js 

I think the -i switch isn't registered as it falls over saying that "File changed: src/models/user.js", which it did.

@tungv
Copy link
Contributor

tungv commented Oct 18, 2017

since -i receive a pattern matching absolute paths, so you have to start with **.

Btw, if you really want to change the content of src/models/user.js, I don't think micro-dev hot reload model would work.

@sholtomaud
Copy link
Author

brilliant! 👍

@mihaiserban
Copy link

For overwrite error the following example helped me alot.
// OverwriteModelError: Cannot overwrite User model once compiled.

https://github.com/LanmeijingLucky/micro-Mongoose-example

const initColl = () => {
  if(mongoose.models.Log) {
    return mongoose.model('Log')
  }
  else {
    return mongoose.model('Log', LogSchema);
  }
}
module.exports = initColl();

@williamli
Copy link

I use something like


const mongoose = require('mongoose');

var schema = new mongoose.Schema({
  _id: mongoose.Schema.Types.ObjectId,
  title: Array,
  slug: String,
  fields: Array,
  definitions: Array,
  meta: {
    createdAt: Date,
    updatedAt: Date,
    publishAt: Date,
    unpublishAt: Date
  }
});

const getModel = () => {
  if (mongoose.models.Page) {
    return mongoose.model('Page')
  } else {
    return mongoose.model('Page', schema, 'Pages');
  }
}

module.exports = getModel()


const Page = require('./dbSchema.js');

Page.find((err, data) => {...

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

4 participants