Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!