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

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
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
16 Replies
Percy
Percy14mo ago
Project ID: b741e4ae-cac8-410f-a15a-be6e2551fa96
Brody
Brody14mo ago
is the json data sensitive?
Dylan-The-Villian
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"
},
}
"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"
},
}
Brody
Brody14mo ago
well for starters thats not valid json if its not sensitive can you just send the actually file over?
Dylan-The-Villian
Here it is, it is valid json but the part I clipped was not
Brody
Brody14mo ago
and where did you get this command from? mongoimport --jsonArray --db Sectors --collection sector --file sectorA.json
Dylan-The-Villian
I got it from a stackoverflow answer. But now I see the answer is 9 years old. That's probably the issue.
Brody
Brody14mo ago
yeah id look for a more up to data answer
Dylan-The-Villian
I also found this from the official docs
mongoimport --uri
mongodb+srv://<USERNAME>:<PASSWORD>@<CLUSTER_NAME>/<DATABASE> --collection <COLLECTION> --type json --file <FILENAME>
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?
Brody
Brody14mo ago
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
Dylan-The-Villian
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?
Brody
Brody14mo ago
does th version of mongoimport you are using support mongo 4.4?
Dylan-The-Villian
Using MongoDB: 4.4.24 Using Mongosh: 2.0.1 It looks like
Brody
Brody14mo ago
the MONGO_URL contains the password, but its looking like the version of mongoimport you are using isnt fully compatible with mongo 4.4
Dylan-The-Villian
The solution by the way was to add --authenticationDatabase=admin to the command. After that it worked
Brody
Brody14mo ago
awsome, glad you found the solution
Want results from more Discord servers?
Add your server