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

19 messages · Page 1 of 1 (latest)

carmine hamlet
#

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

next archBOT
#

Project ID: b741e4ae-cac8-410f-a15a-be6e2551fa96

dire relicBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

cursive rock
#

is the json data sensitive?

carmine hamlet
#

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"
        },
}
cursive rock
#

well for starters thats not valid json

#

if its not sensitive can you just send the actually file over?

carmine hamlet
cursive rock
#

and where did you get this command from?
mongoimport --jsonArray --db Sectors --collection sector --file sectorA.json

carmine hamlet
#

I got it from a stackoverflow answer. But now I see the answer is 9 years old. That's probably the issue.

cursive rock
#

yeah id look for a more up to data answer

carmine hamlet
#

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?

cursive rock
#

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

carmine hamlet
#

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?

cursive rock
#

does th version of mongoimport you are using support mongo 4.4?

carmine hamlet
#

Using MongoDB: 4.4.24
Using Mongosh: 2.0.1
It looks like

cursive rock
#

the MONGO_URL contains the password, but its looking like the version of mongoimport you are using isnt fully compatible with mongo 4.4

carmine hamlet
#

The solution by the way was to add --authenticationDatabase=admin to the command. After that it worked

dire relicBOT