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

89
Views
Topology is closed

I am new in MongoDB. When I run the code below, I get an errror: Topology is closed. I want to create a document in collection. Why does this happen and how can I fix it? I would appretiate any help.

const { MongoClient } = require('mongodb');
const uri = "mongodb+srv://(login info)@cluster0.56skb.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
client.connect(err => {
 const db = client.db("test");
 async function mongo () {
   await db.collection('a').insertMany([
  { item: "journal",
    qty: 25,
    size: { h: 14, w: 21, uom: "cm" },
    status: "A"},
  { item: "notebook",
    qty: 50,
    size: { h: 8.5, w: 11, uom: "in" },
    status: "A"},
  { item: "paper",
    qty: 100,
    size: { h: 8.5, w: 11, uom: "in" },
    status: "D"},
  { item: "planner",
    qty: 75, size: { h: 22.85, w: 30, uom: "cm" },
    status: "D"},
  { item: "postcard",
    qty: 45,
    size: { h: 10, w: 15.25, uom: "cm" },
    status: "A"}
])
.then(function(result) {
  // process result
})
 }
  mongo()
const collection = client.db("test").collection("devices");
  // perform actions on the collection object
  client.close();
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

1- Check your database name and password.
2- Open Mongodb atlas and in "Network Access", change the IP address as "0.0.0.0/0 (includes your current IP address) ".
3- Maybe you can try adding "await" before client.close().

about 4 years ago · Juan Pablo Isaza 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!