R
Railwayā€¢12mo ago
lasse

Mongoose Bun Connection Erros

So when i use my database uri from mongodb.com it cant connect, but as soon i use one form railway it works. Is this something to do with bun itself or mogoose?. I have checked the uri and i can connect local and in mongodb compass.
No description
37 Replies
Percy
Percyā€¢12mo ago
Project ID: N/A
lasse
lasseā€¢12mo ago
N/A
Brody
Brodyā€¢12mo ago
have you whitelisted 0.0.0.0/0 in atlas?
lasse
lasseā€¢12mo ago
Yes im so confused beacuse everything works local.
Brody
Brodyā€¢12mo ago
whats the host and port atlas gave you?
lasse
lasseā€¢12mo ago
Copied the url and replaced with my password
No description
Fragly
Fraglyā€¢12mo ago
censors everything brody asked for šŸ’€
lasse
lasseā€¢12mo ago
mongodb+srv://username:<password>@cluster0.vnhgi9b.mongodb.net/?retryWrites=true&w=majority
Brody
Brodyā€¢12mo ago
am i to assume mongo's default port?
Fragly
Fraglyā€¢12mo ago
This is super weird because I use Atlas on 100% of my railway projects and I've never had this happen to me
Brody
Brodyā€¢12mo ago
why doesnt the url have the port lol
Fragly
Fraglyā€¢12mo ago
<:moyai_shrug:1106001173279940758>
Brody
Brodyā€¢12mo ago
i need the port lol
lasse
lasseā€¢12mo ago
idk, i just clicked the "connect" and then copied the url also it has worked for over two weeks and out of the blue gives me the errors
Brody
Brodyā€¢12mo ago
can you give me a host you use?
Fragly
Fraglyā€¢12mo ago
ya, let me log into atlas rq
Brody
Brodyā€¢12mo ago
No description
Fragly
Fraglyā€¢12mo ago
mongodb+srv://Alfred:<password>@alfredm0.zhhuqsg.mongodb.net/?retryWrites=true&w=majority
mongodb+srv://Alfred:<password>@alfredm0.zhhuqsg.mongodb.net/?retryWrites=true&w=majority
mongodb+srv://scripter:<password>@clusterm0.p34kuiw.mongodb.net/?retryWrites=true&w=majority
mongodb+srv://scripter:<password>@clusterm0.p34kuiw.mongodb.net/?retryWrites=true&w=majority
here's two different ones
lasse
lasseā€¢12mo ago
Looks like my url
Brody
Brodyā€¢12mo ago
i cant dig those either oh its an SRV lookup
lasse
lasseā€¢12mo ago
mabye i try to setup a new database? Same thing with the new one on atlas. Bruh
Fragly
Fraglyā€¢12mo ago
how do you connect to it in mongoose?
lasse
lasseā€¢12mo ago
i have a function in a file called database.ts
import mongoose from "mongoose";

export const connect = async () => {
await mongoose.connect(Bun.env.DATABASE_URL);

// Check if database is connected
if (mongoose.connection.readyState === 1) {
console.log("Database connected");
} else {
console.log("Database not connected");
}
};
import mongoose from "mongoose";

export const connect = async () => {
await mongoose.connect(Bun.env.DATABASE_URL);

// Check if database is connected
if (mongoose.connection.readyState === 1) {
console.log("Database connected");
} else {
console.log("Database not connected");
}
};
and then call it in my index.ts
Fragly
Fraglyā€¢12mo ago
try slapping
mongoose.set('strictQuery', false)
mongoose.set('strictQuery', false)
in there before you run mongoose.connect just an experiment
lasse
lasseā€¢12mo ago
okay like this?
await mongoose.connect(Bun.env.DATABASE_URL as string);
mongoose.set("strictQuery", false);
await mongoose.connect(Bun.env.DATABASE_URL as string);
mongoose.set("strictQuery", false);
Fragly
Fraglyā€¢12mo ago
no, beforer
lasse
lasseā€¢12mo ago
arr alr let me try yhat The same thing
Fragly
Fraglyā€¢12mo ago
dang I guess you're cursed
Fragly
Fraglyā€¢12mo ago
No description
lasse
lasseā€¢12mo ago
lol yea, and mongodb on railway is expensive
Fragly
Fraglyā€¢12mo ago
faxx
Brody
Brodyā€¢12mo ago
youre just trading resource usage for egress usage
Fragly
Fraglyā€¢12mo ago
Just store your data in json files in a shake the Fragly-way
lasse
lasseā€¢12mo ago
ohhh cool i will keep trying to make it work šŸ’€ @Fragly @Brody I cant figure out why its not working. I have created a whole new database and still throwing the same error. I can give access to the github-repo, and if if some of you want to check the code if you should be any mistakes i have maked.
Brody
Brodyā€¢12mo ago
sorry I don't know bun, but I know fragly doesn't use bun, can you try with nodejs?
lasse
lasseā€¢11mo ago
Hey sorry for late response. But its fixed now. Mongodb gave me an uri that worked.
Fragly
Fraglyā€¢11mo ago
oh sick guess we'll never know why it wasn't working before WHYYYYY
Want results from more Discord servers?
Add your server