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
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-be6e2551fa9616 Replies
Project ID:
b741e4ae-cac8-410f-a15a-be6e2551fa96
is the json data sensitive?
No, it's just a very long file.
It's 3 objects that are full of objects,here's the format.
well for starters thats not valid json
if its not sensitive can you just send the actually file over?
Here it is, it is valid json but the part I clipped was not
and where did you get this command from?
mongoimport --jsonArray --db Sectors --collection sector --file sectorA.json
I got it from a stackoverflow answer. But now I see the answer is 9 years old. That's probably the issue.
yeah id look for a more up to data answer
I also found this from the official docs
But it is throwing an error with the --uri
Should I be using the railway cli for this? Is there a railyway specific command?
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 linuxSo 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?does th version of mongoimport you are using support mongo 4.4?
Using MongoDB: 4.4.24
Using Mongosh: 2.0.1
It looks like
the
MONGO_URL
contains the password, but its looking like the version of mongoimport you are using isnt fully compatible with mongo 4.4The solution by the way was to add
--authenticationDatabase=admin
to the command. After that it workedawsome, glad you found the solution