vinzce
vinzce2w ago

Unable to connect to Atlas in typescript Mongodb

Hello ! I am trying to get data from Atlas Mongodb with Typescript using this code : import * as wmill from "https://deno.land/x/windmill@v1.450.0/mod.ts"; // import { MongoClient } from "https://deno.land/x/mongo@v0.34.0/mod.ts"; export async function main( ) { const client = new MongoClient(); const mongodb_connexion = "mongodb+srv://<username>:<password>@cluster0.aavzxle.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"; // Connecting to a Mongo Atlas Database
const resp = await client.connect(mongodb_connexion) .catch((err) => { console.log(err) }) }
but this is not working throwing this error : Error: MongoError: "Connection failed: failed to lookup address information: No address associated with hostname" at MongoClient.connect (https://deno.land/x/mongo@v0.34.0/src/client.ts:61:13) The same code adapted for Python is working perfectly. so it is sure there is nothing wrong on the Atlas Mongodb Side. I have whitelisted worker IPs. Any idea or example ? And in addition, I executed far too many runs of the typescript code, I reached the quota of executions : 1050/1000 user execs 1050/1000 free workspace execs By the way what is the difference between user execs and workspace execs ? Also it seems that execs are counted by seconds of execution. So if one run lasts 1m30, it is counted as 90 execs ? Thanks.
1 Reply
sledge
sledge2w ago
That lib is way outdated ... use the current npm lib: import { MongoClient } from "npm:mongodb"; Then:
const mongo = await wmill.getVariable<string>("f/settings/mongodb");
const client = new MongoClient(mongo);
await client.connect();
const mongo = await wmill.getVariable<string>("f/settings/mongodb");
const client = new MongoClient(mongo);
await client.connect();

Did you find this page helpful?