mongo
mongo copied to clipboard
Mongo Error on Deno runtime
Hello I have tried to run a project on deno, but I receive the following error when trying to run it using "deno"
error: Uncaught Error: MongoError: "Connection failed: Connection refused (os error 111)"
throw new MongoError(`Connection failed: ${e.message || e}`);
^
at MongoClient.connect (client.ts:93:15)
at async db.ts:5:12
Note:
I have tried it several times but the problem still persists.
Thanks in advance
May I know how do you use it?
Expanding upon @hackers267, show your code. It's possible that the hostname/port is incorrect
Thanks for the reply
I have allocated a separate module for database namely db.ts
import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
const client = new MongoClient();
// await client.connect("mongodb://localhost:27017");
const db = await client.connect("mongodb://localhost:27017/kayran");
export * from "https://deno.land/x/[email protected]/mod.ts";
export default db;
Please note that, I did successfully launched my project but after a few re-run deno stopped creating the server and currently it is showing the above error
Thank you
If you used os is window. Try replace localhost with 127.0.0.1
My OS is "Linux Manjaro" and I can run the project on the "Ubuntu" without any problem
Make sure mongo is running by using sudo service mongodb start
command
Faced the same situation on windows 10 and can confirm that changing localhost
to 127.0.0.1
solved the issue @NaderBhrr
If you used os is window. Try replace localhost with 127.0.0.1
This trick solved my problem on Ubuntu as well
I have the same problem on ubuntu, but I don't think it's an issue with this driver.
When I run Deno.connect({hostname: "<domain name of our database", port: 27017})
I'm getting the same os error 111.
Connecting to the ip directly also fixes it for me, and connecting from my local machine to the domain name also works just fine.
It turns out this was caused by ipv6 somehow. When I created a digitalocean droplet without ipv6 support it was able to connect to the server again.
edit: Seems like enabling ipv6 in the mongodb configuration file fixed it.