Cesar
Cesar
DDeno
Created by Cesar on 3/6/2024 in #help
Error connecting to mongoose when using deno cli
deno-x86_64-pc-windows-msvc v1.41.1 Testing the following code using nodejs and on deno deploy works correctly:
import express from 'express';
import mongoose from 'mongoose';

const app = express();
await mongoose.connect("mongodb+srv://...");
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('Connected to MongoDB');
});

app.listen(3001, () => { console.log('starting...'); });
import express from 'express';
import mongoose from 'mongoose';

const app = express();
await mongoose.connect("mongodb+srv://...");
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('Connected to MongoDB');
});

app.listen(3001, () => { console.log('starting...'); });
But when testing using deno cli it doesn't work. I get the message on the console starting... but not the connection error: neither Connected to MongoDB And after some time I get this error:
error: Uncaught (in promise) MongooseServerSelectionError: connection timed out
at _handleConnectionErrors (file:///.../node_modules/.deno/mongoose@8.2.1/node_modules/mongoose/lib/connection.js:875:11)
error: Uncaught (in promise) MongooseServerSelectionError: connection timed out
at _handleConnectionErrors (file:///.../node_modules/.deno/mongoose@8.2.1/node_modules/mongoose/lib/connection.js:875:11)
The same thing happens using mongodb instead of mongoose:
import express from 'express';
import mongodb from 'mongodb';

const app = express();
const client = new mongodb.MongoClient("mongodb+srv://...")
await client.connect();
const db = client.db();

app.listen(3001, () => { console.log('starting...'); });
import express from 'express';
import mongodb from 'mongodb';

const app = express();
const client = new mongodb.MongoClient("mongodb+srv://...")
await client.connect();
const db = client.db();

app.listen(3001, () => { console.log('starting...'); });
C:\Windows\system32>deno run --allow-all ...\index.js
Warning: Not implemented: ClientRequest.options.createConnection
error: Uncaught (in promise) MongoServerSelectionError: connection timed out
at AbortSignal.<anonymous> (file:///...node_modules/.deno/mongodb@6.4.0/node_modules/mongodb/lib/sdam/topology.js:292:34)
C:\Windows\system32>deno run --allow-all ...\index.js
Warning: Not implemented: ClientRequest.options.createConnection
error: Uncaught (in promise) MongoServerSelectionError: connection timed out
at AbortSignal.<anonymous> (file:///...node_modules/.deno/mongodb@6.4.0/node_modules/mongodb/lib/sdam/topology.js:292:34)
I'm starting the script as
deno run --allow-all ...\index.js
deno run --allow-all ...\index.js
I also tested running it as admin, on the Mongo website I have all ip whitelisted Why do I get this error only on the CLI version?
82 replies