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

161
Visualizações
Why can't I connect to mongoDB atlas?

I am new in MongoDB, all my life I used MySQL.

I have created an account in atlas, set the IP to my IP and created a user and saved the password.

here is my code, why doesn't it work?

app.js

const express = require('express');
const bodyParser = require('body-parser');
const mongoPractice = require('./mongo');


const app = express();

app.use(bodyParser.json());

app.post('/products', mongoPractice.createProduct);

app.get('/products');

app.listen(3000);

and the mongo.js:

const MongoClient = require("mongodb").MongoClient;

const url =
  "mongodb+srv://idan:<85IwoSzeQssHMzLN>@cluster0.tpejv.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const createProduct = async (req, res, next) => {
  const newProduct = {
    name: req.body.name,
    price: req.body.price,
  };
  const client = new MongoClient(url);

  try {
    await client.connect();
    const db = client.db();
    const result = db.collection("products").insertOne(newProduct);
  } catch (error) {
    return res.json(error);
  }
  client.close();

  res.json(newProduct);
};

const getProducts = async (req, res, next) => {};

exports.createProduct = createProduct;
exports.getProducts = getProducts;

the POSTMAN output:

enter image description here

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

0

Your ip may have changed, (check if the current ip address has information "(includes your current IP address)". For testing(!) you can add address 0.0.0.0/0 to the whitelist - it means every ip will be accepted - this solution is good for beginners

over 4 years ago · Santiago Trujillo Relatório

0

  1. Firstly check you connection link from mongodb connect
  2. Check username, password again
  3. You can change password and try again
over 4 years ago · Santiago Trujillo Relatório

0

In mongo.js

You need to remove "< >" around the password.

const url = "mongodb+srv://idan:**85IwoSzeQssHMzLN**@cluster0.tpejv.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
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