Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda