Cesar
Cesar
Explore posts from servers
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/[email protected]/node_modules/mongoose/lib/connection.js:875:11)
error: Uncaught (in promise) MongooseServerSelectionError: connection timed out
at _handleConnectionErrors (file:///.../node_modules/.deno/[email protected]/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/[email protected]/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/[email protected]/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
DIAdiscord.js - Imagine an app
Created by Cesar on 2/6/2024 in #djs-questions
Bot permissions
No description
32 replies
DIAdiscord.js - Imagine an app
Created by Cesar on 1/31/2024 in #djs-questions
Hosting on Deno Deploy
I'm hosting my bot on Deno Deploy https://deno.com/deploy it's working great but after some time it goes offline. I tried:
client.on('disconnect', () =>
{
console.log('Bot is disconnected, attempting to reconnect...');
client.login('...').catch(console.error);
});


client.login('...');
client.on('disconnect', () =>
{
console.log('Bot is disconnected, attempting to reconnect...');
client.login('...').catch(console.error);
});


client.login('...');
but the 'disconnect' event is not getting fired. What else could i try to make it keep online?
57 replies