New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MongoError: Topology is closed, please connect #290
Comments
did u got solved @GodBleak ... |
@ganeshtedi I moved on from monk when I closed this. I used MongoJS and got the same issue. I figured out that in MongoDB Atlas I couldn't use the URI string for version "3.0 or later" the URI string for version "2.2.12 or later" Looks like this: |
I am still stuck on this issue as well. how i defined my mongo connection:" how i defined my query:" error: " |
@shaqshaw1 what does your keys.mongoURI look like? |
Try connecting using MongoClient, in this manner :- const MongoClient = require('mongodb').MongoClient; const client = new MongoClient(, { useNewUrlParser: true, useUnifiedTopology: true }); client.connect( err =>{ |
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://root:<password>@cluster0.vksdv.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
client.connect(err => {
const collection = client.db("chatapp").collection("chat");
// perform actions on the collection object
try {
collection.insertOne( { item: "card", qty: 15 } );
} catch {
throw(err)
}
console.log('connected')
});
checked db names etc |
Getting the same thing when trying to preform:
|
mongodb-client does not allow for multiple connections to be on. So empty the 'finally' block by removing client.close. It worked for me but the warnings are still persisting. |
async function insertOne(doc: any) : Promise<void>
{
let client: MongoClient | undefined;
try {
client = await MongoClient.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
});
// OR
client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
});
await client = client.connect();
const col = client.db("mydb").collection("mycol");
await col.insertOne(doc);
}
finally {
if(client)
await client.close();
}
} |
Sometimes the incorrect password or database name or collections name occurs this error. However, you can add allow access from anywhere to resolve this issue. |
Even I got the same error as @GodBleak , then I opened Mongodb atlas and in "Network Access", I changed the IP address as "0.0.0.0/0 (includes your current IP address) ". Then my problem got resolved. |
@yashwanth2407 is there any way to do this without using aMongodb atlas? A command? |
@rav3n11 This opens your database instance to anyone on the Internet to probe for vulnerabilities. Not a good idea to follow this advice in any form. |
Hi, I am receiving this error when inserting a document
MongoError: Topology is closed, please connect
This is my code
What have I done wrong?
The text was updated successfully, but these errors were encountered: