mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

Error inserting into databases on atlas using options for connection creditials

Open joshuaanthonydeleon opened this issue 8 years ago • 5 comments

"mongoose": "^5.2.13" NodeJS - v8.11.4 Mongodb - MongoDB shell version v3.6.1 Do you want to request a feature or report a bug? Bug report What is the current behavior? When saving data into database, connecting to the database works perfectly, I get the result of "MongoError: user is not allowed to do action [insert] on [database]" - this seems to be a issue with passing the basic uri with no options attached to it and options added via the option object parameter.

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

    private async init() {
        const options = {
            authSource: 'admin',
            useNewUrlParser: true,
            user: settings.MongoUser,
            pass: settings.MongoPwd,
            dbName: 'UserAccounts',
            keepAlive: 300000,
            poolSize: 10,
            ssl: true,
            replicaSet: 'replicaSetName'
        }

        await mongoose.connect("mongodb+srv://addresstoatlasDB.net/", options)
            .then((db) => {
                console.log('Connected to mongoDB');
                this._connection = db;
            })
            .catch((err) => {
                console.log('Could not connect to mongoDB');
                throw new Error(err);
            });
    }

What is the expected behavior? Expected behavior is for json data passed through to be saved to the database and not rejected as outlined above.

joshuaanthonydeleon avatar Sep 28 '18 04:09 joshuaanthonydeleon

@joshuaanthonydeleon this should be fixed as of 5.2.16 ( related to #6881 ), can you upgrade to mongoose@latest and verify?

ghost avatar Sep 28 '18 10:09 ghost

@lineus I've updated to package 5.2.18 and the error still persists. Is there additional info I can give to help?

joshuaanthonydeleon avatar Sep 28 '18 13:09 joshuaanthonydeleon

@joshuaanthonydeleon you're right, I don't think the underlying driver bug was fixed as I can still reproduce this with the latest version of the native driver and useNewUrlParser = true.

I'm going to reopen #6881 and I've already reached out the native driver folks about the issue here

ghost avatar Sep 28 '18 14:09 ghost

@lineus thanks for the link. I'll be following along as well.

joshuaanthonydeleon avatar Sep 28 '18 15:09 joshuaanthonydeleon

I'm going to close this since we have #6881 opened back up. Apologies for closing that one without explicitly testing the native driver fix. Thanks for pointing it out @joshuaanthonydeleon !

ghost avatar Sep 28 '18 15:09 ghost