MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

Unable to write to migrated Mongo Atlas Database

I followed the Mlab migration guide to migrate a Mlab Sandbox database to an Atlas. When I use the provided connection string in my application, I am unable to write to the database. I can only read from it.

I do something like below

const toSave = new Model({key: value});
toSave.save()

Error

{
    "message": {
        "operationTime": "6890830329813139457",
        "ok": 0,
        "code": 13,
        "codeName": "Unauthorized",
        "$clusterTime": {
            "clusterTime": "6890830329813139457",
        },
        "name": "MongoError"
    }
}

Additional Info

I can read from the database

I can read and write to the database from the terminal, I can’t write with my application

Ubuntu 16 LTS

Network access is at allow all 0.0.0.0/0 (includes your current IP address)

User access: readWriteAnyDatabase@admin

Mongoose version: v5.10

MongoDB server version v4.2

Type: Replica set

Cluster Tier: M0 Sandbox (General)

Connection string: mongodb+srv://username:password@staging.7gekl.mongodb.net/dbname?retryWrites=true&w=majority

Just a wild guess, there’s something in your connection string that isn’t being passed by your application correctly (you didn’t say what language) e.g., a metachar.

In any case, if you just want to brute-force debug it, try giving the user atlasAdmin privileges once and see if it works.

If it doesn’t work, I suppose it’s telling you the truth: you’re genuinely not authorized. In which case it’s back for looking for the metachar in your password that doesn’t work passed in a string in the language you are using.

Again, just a guess.

Hello,

Can you email support@mlab.com? We’ll be happy to help troubleshoot.

1 Like