R
Railway

✋|help

How can I add a json file to my mongoDB with railway?

D.dylangm9/19/2023
I have a json file containing all of the record my project needs, it is called sectorA I want to add this to the database. I have been trying to use this command
mongoimport --jsonArray --db Sectors --collection sector --file sectorA.json

My termnial is telling me my command is: SyntaxError: Missing semicolon. (1:14) but when I add a semicolon the error just moves forward a place.
What am I missing here? Here is my project ID: b741e4ae-cac8-410f-a15a-be6e2551fa96
BBrody9/20/2023
is the json data sensitive?
D.dylangm9/20/2023
No, it's just a very long file.
It's 3 objects that are full of objects,here's the format.
"systems": [
        {
            "systemStar": "Brown-Dwarf",
            "systemName": "Theaie",
            "systemPlanets": [
                {
                    "name": "Theaie-1",
                    "class": "Frozen5",
                    "naturalResources": [
                        "water",
                        "ore"
                    ],
                    "buildings": [],
                    "resourceStorage": [],
                    "production": [],
                    "orbit": [],
                    "hangar": [],
                    "ownership": "unowned"
                }
            ],
            "cords": "R-7830"
        },
}
BBrody9/20/2023
well for starters thats not valid json
if its not sensitive can you just send the actually file over?
D.dylangm9/20/2023
Here it is, it is valid json but the part I clipped was not
BBrody9/20/2023
and where did you get this command from?
mongoimport --jsonArray --db Sectors --collection sector --file sectorA.json
D.dylangm9/20/2023
I got it from a stackoverflow answer. But now I see the answer is 9 years old. That's probably the issue.
BBrody9/20/2023
yeah id look for a more up to data answer
D.dylangm9/20/2023
I also found this from the official docs
mongoimport --uri 
mongodb+srv://<USERNAME>:<PASSWORD>@<CLUSTER_NAME>/<DATABASE> --collection <COLLECTION> --type json --file <FILENAME>

But it is throwing an error with the --uri
Should I be using the railway cli for this? Is there a railyway specific command?
BBrody9/20/2023
yes you should that way you wont have to manually copy around your connection string
assuming you have a MONGO_URL reference variable added to your service you could run
railway run mongoimport --uri $MONGO_URL --collection <COLLECTION> --type json --file <FILENAME>
thats also assuming that command is correct and ran on linux
D.dylangm9/20/2023
So after running that I get this error connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
I'm guessing I need to put my password in there, right? Or is there a setting in railway I need to tweak?
BBrody9/20/2023
does th version of mongoimport you are using support mongo 4.4?
D.dylangm9/20/2023
Using MongoDB: 4.4.24
Using Mongosh: 2.0.1
It looks like
BBrody9/20/2023
the MONGO_URL contains the password, but its looking like the version of mongoimport you are using isnt fully compatible with mongo 4.4
D.dylangm9/20/2023
The solution by the way was to add --authenticationDatabase=admin to the command. After that it worked
BBrody9/20/2023
awsome, glad you found the solution

Looking for more? Join the community!

Recommended Posts
could not receive data from client: Connection reset by peerI'm having issues with the DB connection, keep getting: `could not receive data from client: Connectjava.lang.UnsupportedClassVersionErrorHow fix it? I use java 19Add domain to webapp - how?I initially (½ year ago), added my domain under settings - setup the records as described, and it waError adding TCP proxy - Not AuthorizedHello I deployed a service based on a docker image, in order to connect to the service I try to set A way to increase the build timeoutI would like to know if there is a way to increase the build timeout, as I have a very large nextjs TLS handshake timeout during transition from build to deployMy sites have been failing to deploy the whole day + yesterday. I see that this was an issue multiplsave file on file system not foundi've create api to save file to public files after i upload new file on railway host, 404 where i Can I create an environment from a secondary branch of a GitHub repository?Hello, I have a Node.js web app on Railway, and I'm looking for a way to create a second instance fServer becomes unresponsiveCan someone please help me figure out what occurred Saturday? Our production site was not accessibleProject with cron job aways skippedWhy my project nevers run with cronMaximum of 4 volumes per project?Heya 🌞 I have several services and would need to attach another volume to one of these but it get aAny way to skip redeployment if github ci is skipped?Here's what I see on dashboard, railway is granted all accesses in my org on github. On github I caBuild Error after RedeployRecently, I've been facing a weird error whenever I redeploy my railway instance from the dashboard.Restarting database not working.My postgres database wont restart. All data is not modifiy after restaring it.Adding support for python with isolated-vm npm packageHello, I am using a project that requires the isolated-vm npm package (https://www.npmjs.com/packageListmonk; Static FilesNot sure why my post was deleted, but here it is again: Hello, I've deployed Listmonk on Railway, ConcurrencyWill concurrent requests to a single endpoint work? And where would the logs appear for each individProblem with Flask-Caching/ RedisI'm trying to setup a simple caching mecanism to my Plotly Dash (Flask) application deployed to railWorker Killed IssueI'm getting the attached error when I try to request my app from a React frontend, whereas I wasn't Need help with deploymentSubject: Seeking Guidance on Loading Environment Variables in Railway for My Go API Deployment Hi e