R
Railway4mo ago
Troy

Enable replica sets for a single MongoDB instance

Hi, i'm getting this issue in my code with MongoDB 2024/07/28 23:24:54 (Location40573) The $changeStream stage is only supported on replica sets I'm unsure how to approach this using native Railway MongoDB as I had been using DigitalOcean prior to this and they just configured it for me automatically. Tried adding an environmental variable for REPLICA_SET_NAME but that didn't do anything. Just needed for 1 mongo instance. Any help is appreciated.
64 Replies
Percy
Percy4mo ago
Project ID: N/A
Troy
TroyOP4mo ago
N/A
Brody
Brody4mo ago
the replicas option you see in your service settings has absolutely nothing to do with mongo replicas despite the same name, and it's absolutely not what you want. are you using prisma?
Troy
TroyOP4mo ago
I dont think so whats prisma?
Brody
Brody4mo ago
an orm
Troy
TroyOP4mo ago
no quite simply all i did was plug in the mongodb private uri from railway in place of the one i got from digitalocean thats when i started getting that errror
Brody
Brody4mo ago
something in your code requires a mongo replica set, you have a few options- - remove that requirement - deploy the mongo replica set template - continue using the digital ocean database
Troy
TroyOP4mo ago
i deployed the template but it's 3 instances, i only need 1 i deleted 2 of them and now it errors this: 2024/07/29 00:09:30 server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: mongo1.railway.internal:27017, Type: RSGhost, Average RTT: 1288054 }, { Addr: :27017, Type: Unknown, Last error: dial tcp :27017: connect: connection refused }, { Addr: :27017, Type: Unknown }, ] }
Brody
Brody4mo ago
that's what a mongo replica set is, you can not just delete them
Troy
TroyOP4mo ago
oh so i connect to the url of the top one
Brody
Brody4mo ago
correct
Troy
TroyOP4mo ago
will this be a lot costlier in terms of resources?
Brody
Brody4mo ago
Vs digital ocean, not sure, never ran a database on DO
Troy
TroyOP4mo ago
$15/mo is what im currently paying its on the more expensive side i just did it with the free credit when i started and didnt care enough to switch
Brody
Brody4mo ago
then it's likely you will pay less for the database on railway, but that's not a promise
Troy
TroyOP4mo ago
yeah fair enough
Brody
Brody4mo ago
plus you will not be charged egress fees for communicating with an external database
Troy
TroyOP4mo ago
true this looks ok so far thanks man btw another thing ive been wondering you may be able to answer, when i use log,Println in Go it makes the logs red for some reason on the railway UI do u know why?
Brody
Brody4mo ago
because that logs to stderr you can create your own logger and set the output to stdout
Troy
TroyOP4mo ago
Ok thanks
Brody
Brody4mo ago
no problem!
Troy
TroyOP4mo ago
would something like fmt.Println log to stdout native?
Brody
Brody4mo ago
correct
Troy
TroyOP4mo ago
oh so i dont have to make my own logger ill just change them all to that perfect
Brody
Brody4mo ago
if you don't actually need a logging framework, yes though id highly recommend looking into slog, railway has great support for structured logging
Troy
TroyOP4mo ago
good to know just was a lot easier for me to mindlessly spam log.println
Brody
Brody4mo ago
I feel ya
Troy
TroyOP4mo ago
Hey Brody i have a follow up question
Troy
TroyOP4mo ago
I'm trying to get into this replicaset db with mongodb compass
No description
Troy
TroyOP4mo ago
I'm copying this on Mongo1
No description
Brody
Brody4mo ago
you would need to use the public host and port
Troy
TroyOP4mo ago
Where can I find that?
Brody
Brody4mo ago
In the service settings I think that template comes with a public TCP proxy
Troy
TroyOP4mo ago
No description
Troy
TroyOP4mo ago
Oh so its this port smae host it appears just a diff port
Brody
Brody4mo ago
yes correct that's a different bost
Troy
TroyOP4mo ago
kk mongodb makes everything so complicated never using that shit again lol
Brody
Brody4mo ago
Postgres FTW
Troy
TroyOP4mo ago
yeah i just im spending so mch money just to keep this app even running i cant afford to go recode it rn
Brody
Brody4mo ago
Thats fair
Troy
TroyOP4mo ago
railway doesnt support static ips right google said it doesnt
Brody
Brody4mo ago
You can get a static outbound ip on the Pro plan
Troy
TroyOP4mo ago
whole reason im even not using my digitalocean db rn is because it requires you to access from a certain ip oh yeah?
Troy
TroyOP4mo ago
ahh im gonna go bankrupt
Brody
Brody4mo ago
whats your usecase for static outbound ips?
Troy
TroyOP4mo ago
digitalocean has a whitelist for IPs where im hosting the managed db seems a lot easier than going through this whole headache
Brody
Brody4mo ago
May I ask whats tricky about the mongo replica set template?
Troy
TroyOP4mo ago
just doesnt work for me man i have a full time job im completely drained cant sit down for 3 hours and figure this out
Brody
Brody4mo ago
Care to share what there is to figure out? would love to know how we can improve the template
Troy
TroyOP4mo ago
i mean for me its just like the simplicity of just being able to copy the url on the DO managed service paste it in and have it work first time was incredible thats the point of a managed service obviously but i guess the way they presented it was just less outwardly intimidating i also noticed that once i removed the deployments i couldnt seem to get it back on
Brody
Brody4mo ago
hmm, does the template not come with a public url? you can! click the removed deployments 3-dot menu and then click redeploy
Troy
TroyOP4mo ago
thats what i was using but it didnt work to try and get into my mongodb compass, etc bc also for the replica set it doesnt supply a db ui
Brody
Brody4mo ago
that was a private url
Troy
TroyOP4mo ago
the way it does for the singular mongodb instance no i was using the regular one i deleted it now but i saw there was a private one too it isnt the one i was using
Brody
Brody4mo ago
this is a private domain
Troy
TroyOP4mo ago
yeah thats why i got weirded out it isnt the domain i plugged in like i used the public one and it gave me that error message
Brody
Brody4mo ago
you would have had to put the internal domain in compass in one way or another
Troy
TroyOP4mo ago
i put this domain
Troy
TroyOP4mo ago
No description
Troy
TroyOP4mo ago
look i still have it
Brody
Brody4mo ago
odd, guess compass had something cached
Troy
TroyOP4mo ago
maybe im gonna just do this railway migration when my business is not bleeding cash lol too stressed to deal with it
Brody
Brody4mo ago
Fair enough
Want results from more Discord servers?
Add your server