Enable replica sets for a single MongoDB instance

AnonymousTRIAL

10 months ago

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 REPLICASETNAME but that didn't do anything. Just needed for 1 mongo instance. Any help is appreciated.

0 Replies

AnonymousTRIAL

10 months ago

N/A


10 months 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?


AnonymousTRIAL

10 months ago

I dont think so


AnonymousTRIAL

10 months ago

whats prisma?


10 months ago

an orm


AnonymousTRIAL

10 months ago

no


AnonymousTRIAL

10 months ago

quite simply all i did was plug in the mongodb private uri from railway in place of the one i got from digitalocean


AnonymousTRIAL

10 months ago

thats when i started getting that errror


10 months 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


AnonymousTRIAL

10 months ago

i deployed the template but it's 3 instances, i only need 1


AnonymousTRIAL

10 months ago

i deleted 2 of them


AnonymousTRIAL

10 months ago

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 }, ] }


10 months ago

that's what a mongo replica set is, you can not just delete them


AnonymousTRIAL

10 months ago

oh


AnonymousTRIAL

10 months ago

so i connect to the url of the top one


10 months ago

correct


AnonymousTRIAL

10 months ago

will this be a lot costlier in terms of resources?


10 months ago

Vs digital ocean, not sure, never ran a database on DO


AnonymousTRIAL

10 months ago

$15/mo is what im currently paying


AnonymousTRIAL

10 months ago

its on the more expensive side i just did it with the free credit when i started and didnt care enough to switch


10 months ago

then it's likely you will pay less for the database on railway, but that's not a promise


AnonymousTRIAL

10 months ago

yeah fair enough


10 months ago

plus you will not be charged egress fees for communicating with an external database


AnonymousTRIAL

10 months ago

true


AnonymousTRIAL

10 months ago

this looks ok so far


AnonymousTRIAL

10 months ago

thanks man


AnonymousTRIAL

10 months ago

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


AnonymousTRIAL

10 months ago

do u know why?


10 months ago

because that logs to stderr


10 months ago

you can create your own logger and set the output to stdout


AnonymousTRIAL

10 months ago

Ok


AnonymousTRIAL

10 months ago

thanks


10 months ago

no problem!


AnonymousTRIAL

10 months ago

would something like


AnonymousTRIAL

10 months ago

fmt.Println


AnonymousTRIAL

10 months ago

log to stdout native?


10 months ago

correct


AnonymousTRIAL

10 months ago

oh


AnonymousTRIAL

10 months ago

so i dont have to make my own logger ill just change them all to that


AnonymousTRIAL

10 months ago

perfect


10 months ago

if you don't actually need a logging framework, yes


10 months ago

though id highly recommend looking into slog, railway has great support for structured logging


AnonymousTRIAL

10 months ago

good to know


AnonymousTRIAL

10 months ago

just was a lot easier for me to mindlessly spam log.println


10 months ago

I feel ya


AnonymousTRIAL

10 months ago

Hey Brody i have a follow up question


AnonymousTRIAL

10 months ago

I'm trying to get into this replicaset db with mongodb compass

1267638656198381600


AnonymousTRIAL

10 months ago

I'm copying this on Mongo1

1267638764944101600


10 months ago

you would need to use the public host and port


AnonymousTRIAL

10 months ago

Where can I find that?


10 months ago

In the service settings


10 months ago

I think that template comes with a public TCP proxy


AnonymousTRIAL

10 months ago

1267639348103352300


AnonymousTRIAL

10 months ago

Oh so its this port


AnonymousTRIAL

10 months ago

smae host it appears just a diff port


10 months ago

yes correct


10 months ago

that's a different bost


AnonymousTRIAL

10 months ago

kk


AnonymousTRIAL

10 months ago

mongodb makes everything so complicated


AnonymousTRIAL

10 months ago

never using that shit again lol


10 months ago

Postgres FTW


AnonymousTRIAL

10 months ago

yeah i just


AnonymousTRIAL

10 months ago

im spending so mch money


AnonymousTRIAL

10 months ago

just to keep this app even running


AnonymousTRIAL

10 months ago

i cant afford to go recode it rn


10 months ago

Thats fair


AnonymousTRIAL

10 months ago

railway doesnt support static ips right


AnonymousTRIAL

10 months ago

google said it doesnt


10 months ago

You can get a static outbound ip on the Pro plan


AnonymousTRIAL

10 months ago

whole reason im even not using my digitalocean db rn is because it requires you to access from a certain ip


AnonymousTRIAL

10 months ago

oh yeah?


10 months ago

yeah -


AnonymousTRIAL

10 months ago

ahh im gonna go bankrupt


10 months ago

whats your usecase for static outbound ips?


AnonymousTRIAL

10 months ago

digitalocean has a whitelist for IPs


AnonymousTRIAL

10 months ago

where im hosting the managed db


AnonymousTRIAL

10 months ago

seems a lot easier than going through this whole headache


10 months ago

May I ask whats tricky about the mongo replica set template?


AnonymousTRIAL

10 months ago

just doesnt work for me man


AnonymousTRIAL

10 months ago

i have a full time job im completely drained


AnonymousTRIAL

10 months ago

cant sit down for 3 hours and figure this out


10 months ago

Care to share what there is to figure out? would love to know how we can improve the template


AnonymousTRIAL

10 months ago

i mean for me its just like


AnonymousTRIAL

10 months ago

the simplicity of just being able to copy the url on the DO managed service


AnonymousTRIAL

10 months ago

paste it in and have it work first time


AnonymousTRIAL

10 months ago

was incredible


AnonymousTRIAL

10 months ago

thats the point of a managed service obviously but


AnonymousTRIAL

10 months ago

i guess the way they presented it was just less outwardly intimidating


AnonymousTRIAL

10 months ago

i also noticed that once i removed the deployments i couldnt seem to get it back on


10 months ago

hmm, does the template not come with a public url?


10 months ago

you can! click the removed deployments 3-dot menu and then click redeploy


AnonymousTRIAL

10 months ago

thats what i was using but it didnt work


AnonymousTRIAL

10 months ago

to try and get into my mongodb compass, etc


AnonymousTRIAL

10 months ago

bc also for the replica set it doesnt supply a db ui


10 months ago

that was a private url


AnonymousTRIAL

10 months ago

the way it does for the singular mongodb instance


AnonymousTRIAL

10 months ago

no i was using the regular one


AnonymousTRIAL

10 months ago

i deleted it now but i saw there was a private one too it isnt the one i was using


10 months ago

this is a private domain


AnonymousTRIAL

10 months ago

yeah thats why i got weirded out


AnonymousTRIAL

10 months ago

it isnt the domain i plugged in


AnonymousTRIAL

10 months ago

like i used the public one and it gave me that error message


10 months ago

you would have had to put the internal domain in compass in one way or another


AnonymousTRIAL

10 months ago

i put this domain


AnonymousTRIAL

10 months ago

1267647075236057000


AnonymousTRIAL

10 months ago

look i still have it


10 months ago

odd, guess compass had something cached


AnonymousTRIAL

10 months ago

maybe


AnonymousTRIAL

10 months ago

im gonna just do this railway migration


AnonymousTRIAL

10 months ago

when my business is not bleeding cash


AnonymousTRIAL

10 months ago

lol


AnonymousTRIAL

10 months ago

too stressed to deal with it


10 months ago

Fair enough


Enable replica sets for a single MongoDB instance - Railway Help Station