Enable replica sets for a single MongoDB instance
Anonymous
TRIALOP

2 years 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.

113 Replies

Anonymous
TRIALOP

2 years ago

N/A


2 years 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?


Anonymous
TRIALOP

2 years ago

I dont think so


Anonymous
TRIALOP

2 years ago

whats prisma?


2 years ago

an orm


Anonymous
TRIALOP

2 years ago

no


Anonymous
TRIALOP

2 years ago

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


Anonymous
TRIALOP

2 years ago

thats when i started getting that errror


2 years 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


Anonymous
TRIALOP

2 years ago

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


Anonymous
TRIALOP

2 years ago

i deleted 2 of them


Anonymous
TRIALOP

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


2 years ago

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


Anonymous
TRIALOP

2 years ago

oh


Anonymous
TRIALOP

2 years ago

so i connect to the url of the top one


2 years ago

correct


Anonymous
TRIALOP

2 years ago

will this be a lot costlier in terms of resources?


2 years ago

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


Anonymous
TRIALOP

2 years ago

$15/mo is what im currently paying


Anonymous
TRIALOP

2 years ago

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


2 years ago

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


Anonymous
TRIALOP

2 years ago

yeah fair enough


2 years ago

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


Anonymous
TRIALOP

2 years ago

true


Anonymous
TRIALOP

2 years ago

this looks ok so far


Anonymous
TRIALOP

2 years ago

thanks man


Anonymous
TRIALOP

2 years 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


Anonymous
TRIALOP

2 years ago

do u know why?


2 years ago

because that logs to stderr


2 years ago

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


Anonymous
TRIALOP

2 years ago

Ok


Anonymous
TRIALOP

2 years ago

thanks


2 years ago

no problem!


Anonymous
TRIALOP

2 years ago

would something like


Anonymous
TRIALOP

2 years ago

fmt.Println


Anonymous
TRIALOP

2 years ago

log to stdout native?


2 years ago

correct


Anonymous
TRIALOP

2 years ago

oh


Anonymous
TRIALOP

2 years ago

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


Anonymous
TRIALOP

2 years ago

perfect


2 years ago

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


2 years ago

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


Anonymous
TRIALOP

2 years ago

good to know


Anonymous
TRIALOP

2 years ago

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


2 years ago

I feel ya


Anonymous
TRIALOP

2 years ago

Hey Brody i have a follow up question


Anonymous
TRIALOP

2 years ago

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

1267638656198381600


Anonymous
TRIALOP

2 years ago

I'm copying this on Mongo1

1267638764944101600


2 years ago

you would need to use the public host and port


Anonymous
TRIALOP

2 years ago

Where can I find that?


2 years ago

In the service settings


2 years ago

I think that template comes with a public TCP proxy


Anonymous
TRIALOP

2 years ago

1267639348103352300


Anonymous
TRIALOP

2 years ago

Oh so its this port


Anonymous
TRIALOP

2 years ago

smae host it appears just a diff port


2 years ago

yes correct


2 years ago

that's a different bost


Anonymous
TRIALOP

2 years ago

kk


Anonymous
TRIALOP

2 years ago

mongodb makes everything so complicated


Anonymous
TRIALOP

2 years ago

never using that shit again lol


2 years ago

Postgres FTW


Anonymous
TRIALOP

2 years ago

yeah i just


Anonymous
TRIALOP

2 years ago

im spending so mch money


Anonymous
TRIALOP

2 years ago

just to keep this app even running


Anonymous
TRIALOP

2 years ago

i cant afford to go recode it rn


2 years ago

Thats fair


Anonymous
TRIALOP

2 years ago

railway doesnt support static ips right


Anonymous
TRIALOP

2 years ago

google said it doesnt


2 years ago

You can get a static outbound ip on the Pro plan


Anonymous
TRIALOP

2 years ago

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


Anonymous
TRIALOP

2 years ago

oh yeah?


2 years ago

yeah -


Anonymous
TRIALOP

2 years ago

ahh im gonna go bankrupt


2 years ago

whats your usecase for static outbound ips?


Anonymous
TRIALOP

2 years ago

digitalocean has a whitelist for IPs


Anonymous
TRIALOP

2 years ago

where im hosting the managed db


Anonymous
TRIALOP

2 years ago

seems a lot easier than going through this whole headache


2 years ago

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


Anonymous
TRIALOP

2 years ago

just doesnt work for me man


Anonymous
TRIALOP

2 years ago

i have a full time job im completely drained


Anonymous
TRIALOP

2 years ago

cant sit down for 3 hours and figure this out


2 years ago

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


Anonymous
TRIALOP

2 years ago

i mean for me its just like


Anonymous
TRIALOP

2 years ago

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


Anonymous
TRIALOP

2 years ago

paste it in and have it work first time


Anonymous
TRIALOP

2 years ago

was incredible


Anonymous
TRIALOP

2 years ago

thats the point of a managed service obviously but


Anonymous
TRIALOP

2 years ago

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


Anonymous
TRIALOP

2 years ago

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


2 years ago

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


2 years ago

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


Anonymous
TRIALOP

2 years ago

thats what i was using but it didnt work


Anonymous
TRIALOP

2 years ago

to try and get into my mongodb compass, etc


Anonymous
TRIALOP

2 years ago

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


2 years ago

that was a private url


Anonymous
TRIALOP

2 years ago

the way it does for the singular mongodb instance


Anonymous
TRIALOP

2 years ago

no i was using the regular one


Anonymous
TRIALOP

2 years ago

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


2 years ago

this is a private domain


Anonymous
TRIALOP

2 years ago

yeah thats why i got weirded out


Anonymous
TRIALOP

2 years ago

it isnt the domain i plugged in


Anonymous
TRIALOP

2 years ago

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


2 years ago

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


Anonymous
TRIALOP

2 years ago

i put this domain


Anonymous
TRIALOP

2 years ago

1267647075236057000


Anonymous
TRIALOP

2 years ago

look i still have it


2 years ago

odd, guess compass had something cached


Anonymous
TRIALOP

2 years ago

maybe


Anonymous
TRIALOP

2 years ago

im gonna just do this railway migration


Anonymous
TRIALOP

2 years ago

when my business is not bleeding cash


Anonymous
TRIALOP

2 years ago

lol


Anonymous
TRIALOP

2 years ago

too stressed to deal with it


2 years ago

Fair enough


Loading...