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
Project ID:
N/A
N/A
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?
I dont think so
whats prisma?
an orm
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
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
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 }, ] }
that's what a mongo replica set is, you can not just delete them
oh
so i connect to the url of the top one
correct
will this be a lot costlier in terms of resources?
Vs digital ocean, not sure, never ran a database on DO
$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
then it's likely you will pay less for the database on railway, but that's not a promise
yeah fair enough
plus you will not be charged egress fees for communicating with an external database
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?
because that logs to stderr
you can create your own logger and set the output to stdout
Ok
thanks
no problem!
would something like
fmt.Println
log to stdout native?
correct
oh
so i dont have to make my own logger ill just change them all to that
perfect
if you don't actually need a logging framework, yes
though id highly recommend looking into slog, railway has great support for structured logging
good to know
just was a lot easier for me to mindlessly spam log.println
I feel ya
Hey Brody i have a follow up question
I'm trying to get into this replicaset db with mongodb compass
I'm copying this on Mongo1
you would need to use the public host and port
Where can I find that?
In the service settings
I think that template comes with a public TCP proxy
Oh so its this port
smae host it appears just a diff port
yes correct
that's a different bost
kk
mongodb makes everything so complicated
never using that shit again lol
Postgres FTW
yeah i just
im spending so mch money
just to keep this app even running
i cant afford to go recode it rn
Thats fair
railway doesnt support static ips right
google said it doesnt
You can get a static outbound ip on the Pro plan
whole reason im even not using my digitalocean db rn is because it requires you to access from a certain ip
oh yeah?
ahh im gonna go bankrupt
whats your usecase for static outbound ips?
digitalocean has a whitelist for IPs
where im hosting the managed db
seems a lot easier than going through this whole headache
May I ask whats tricky about the mongo replica set template?
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
Care to share what there is to figure out? would love to know how we can improve the template
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
hmm, does the template not come with a public url?
you can! click the removed deployments 3-dot menu and then click redeploy
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
that was a private url
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
this is a private domain
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
you would have had to put the internal domain in compass in one way or another
i put this domain
look i still have it
odd, guess compass had something cached
maybe
im gonna just do this railway migration
when my business is not bleeding cash
lol
too stressed to deal with it
Fair enough