0
votes

I'm new to this and am struggling to get over the first hurdle!

How do you import a json file?

I've tried 'mongoimport --db databasename --collection collectionname --file filename.json --jsonArray'

This has given me the error 'uncaught exception: SyntaxError: unexpected token: identifier : @(shell:1:14)'

Having done more research there's a lot of variations about mongo import but regardless I'm getting the same error!

Any advice would be brilliant, thank you!

1
it sounds like your json is corrupted - dododo

1 Answers

0
votes

First step for above 4.X.X versions in mongodb download the tools from mongo db site. https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools

Second go to the directory installed usually C:\Program Files\MongoDB\Tools\100\bin

Third step copy import.exe file & paste it in C:\Program Files\MongoDB\Server\4.4\bin

then create a db "use restaurant"& create a collection "db.createCollection("rest")

new terminal as admin cmd type this command mongoimport --jsonArray --db restaurant --collection rest --drop --file "C:\Program Files\MongoDB\file1.json" note: this will run provided you have a json file "file1.json" in the location just change the location of your file.