Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

332
Visualizações
mongoose unable to connect authorized db

I installed the mongodb 3.4.1 on the ubuntu 16.04 and hosted them on digital ocean.

My local mongo client was mongochef 4.5.2

At first, I didn’t set up the authorization for my app, it’s hacked, and was asked for bitcoin as ransom.
 So I tried to set up the authorization. However, encountered a wired problem, once set the authorization: enable in the /etc/mongo.conf . It’s unable to connect the db remotely and locally with the mongoose , and got the error auth failed. But it could be connected with the terminal and the mongoChef.

here is my connection with mongoose

global.db=mongoose.connect('mongodb://admin:admin123@ip:27017/nodedb');

and i also tried

var options = {
 user : "admin",
 pass : “admin123",
 auth : {authMechanism: 'MONGODB-CR'}
} global.db = mongoose.connect('mongodb://@ip:27017/test',options);

and also changed the ip with localhost and 127.0.0.1 locally, failed the same.

Just in case the localhost and 127.0.0.1 didn’t recognised. Also set the configuration in the /etc/hosts with:

127.0.0.1 localhost 127.0.0.1 computename

update~:

there are two users in my admin DB. One is root user. And another one is admin with password admin123 which authenticated DB nodedb

really exhausted by this problem, has any one encounter this problem???

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You have not specified the authSource (the database against which it is authenticated). So, if the authSource is admin it should be specified in the connection options.

options = {
    "auth": {
        "authSource": "admin"
    },
    "user": "apiuser",
    "pass": "admin123"
};

// If host=localhost, port=27017 and database name=nodedb
mongoose.connect('mongodb://localhost:27017/nodedb', options);
over 4 years ago · Santiago Trujillo Relatório

0

Authentication is done at a database level. In your connection string db is nodedb, but your password is stored in admin database. You can connect to nodedb either by adding a user to this db or by defining db for auth with --authenticationDatabase admin. You can read more here. For more info, please check manual http://docs.mongodb.org/manual/reference/privilege-documents/

over 4 years ago · Santiago Trujillo Relatório

0

Access your nodedb from terminal(mongosh) then show users. Then check your user roles. Add role for readWrite to user for the nodedb database if it does not exist.

    use nodedb
    show users
    db.grantRolesToUser('admin',[{role:'readWrite', db:'nodedb'}])
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda