Skip to content

Is it possible to remove default empty connection from mongoose.connections? #8302

Closed

Description

Do you want to request a feature or report a bug?
feature
What is the current behavior?
When mongoose is imported in some file, it will automatically call constructor of mongoose, where we have call of createConnection() method, without any uri.

That means that mongoose.connections[0] is a bit useless. So, when I use .createConnection(someUri, options) to have real connection to db and my connection will be on 2nd place in an array of connections. Problem here is that mongoose.model() won't be able to properly instance model, because it will watch default connection, which is equal to mongoose.connections[0]

If the current behavior is a bug, please provide the steps to reproduce.

const mongoose = require('mongoose');

(() => {
  console.log('Number of connections is', mongoose.connections.length); // will print that there is one connection
})();

What is the expected behavior?

Expecting that this default connection disappear from list of connections when real connection is provided and to override mongoose.connection with first connection from list

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node 12.13.0
mongoose 5.7.7
mongoDB 3.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    discussionIf you have any thoughts or comments on this issue, please share them!helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions