I'm using this command
mongoimport --db test --collection bankdata --drop --file bank_data.json --port 27017 --host 127.0.0.1
to import a json file, but when I do it I get this message
Failed: error unmarshaling bytes on document #0: JSON decoder out of sync - data changing underfoot?
2016-05-24T08:00:31.552-0600 imported 0 documents
You are trying to import json array ,so you need to add --jsonArray option according to documentation https://docs.mongodb.com/manual/reference/program/mongoimport/
mongoimport --jsonArray --db test --collection bankdata --drop --file
bank_data.json
Related
mongoimport --uri mongodb+srv://gtye:<PASSWORD>#dxgraph.rymok.mongodb.net/dxgraph-db --collection dxgraph-collection --type json --file ~/DxHero%20Godot/Data/postgres_export.json
returns
2021-05-25T12:58:05.538-0400 Failed: open /Users/gtye/DxHero%20Godot/Data/postgres_export.json: no such file or directory
2021-05-25T12:58:05.538-0400 0 document(s) imported successfully. 0 document(s) failed to import.
But I know it's there!!
It's literally right here!! What the heck is going on?
%20 is a URI escaping mechanism. It doesn't work in the shell.
Try:
mongoimport --uri mongodb+srv://gtye:<PASSWORD>#dxgraph.rymok.mongodb.net/dxgraph-db --collection dxgraph-collection --type json --file ~/"DxHero Godot/Data/postgres_export.json"
I know that we can use the mongoimport command to insert one json file into a mongodb database:
mongoimport --jsonArray --db [dbname] --collection [collectionname] --file filename.json
But are there any command that let me insert multiple json files at once?
On mac
cd jsonfilesfolder
ls -1 *.json | while read jsonfile; do mongoimport -d shop --file $jsonfile --type json; done
Reference
I am a beginner and trying to import data from MongoDB. The Robo3T which I use for visualization shows something like below.
--Kins
Kins
And this is the command I use
mongoexport --db kins --collection test --out output.json
mongoexport --db kins.kins --collection test --out output.json
mongoexport --db [kins].[kins] --collection test --out output.json
But none of them work. What's the correct syntax?
How to import data in json format. Please guide me.
Link I reviewed:
Dump Mongo Collection into JSON format
I guess you want to use the --jsonArray (docs) flag because by default mongoexport writes data using one JSON document for every MongoDB document.
mongoexport --db kins.kins --collection test --out output.json --jsonArray
You can consider using the --pretty (docs) flag too. It will output documents in pretty-printed format.
Trying to import a JSON file
Mongodb Version -- V3.6.3
Shell Version 3.6
Using this command to connect to cluster and import
mongoimport --host cluster0-shard-00-00-xxm0e.mongodb.net:24537 --db ny --type json --file C:/data/docs/ny.json --jsonArray --authenticationDatabase admin --ssl --username xyz --password mongodb
error message
2018-03-03T22:53:45.477-0800 no collection specified
2018-03-03T22:53:45.478-0800 using filename 'ny' as collection
2018-03-03T22:53:46.062-0800 Failed: error connecting to db server: server` returned error on SASL authentication step: bad auth Authentication failed.
2018-03-03T22:53:46.062-0800 imported 0 documents
Have tried a few options like
removing -ssl
adding ----sslAllowInvalidCertificates
Adding " C:/data/docs/ny.json" to file name
and none of these works.. Any help appreciated
You have to specify the collection -c or --collection flag. see official docs.
mongoimport
--host <HOST>
--ssl --username <USERNAME>
--password <PASSWORD>
--authenticationDatabase admin
--db <DATABASE>
--collection <COLLECTION>
--type <FILETYPE>
--file <FILENAME>
You missed specifying the collection name :
mongoimport --host cluster0-shard-00-00-xxm0e.mongodb.net:24537 --db ny --collection <entercollectionName> --type json --file C:/data/docs/ny.json --jsonArray --authenticationDatabase admin --ssl --username xyz --password mongodb
try the command now
For now, we can easy import/export without having to have multiple options like this:
mongoimport --uri mongodb+srv://<USERNAME>:<PASSWORD>#your-cluster.mongodb.net/<DATABASE_NAME> --collection <COLLECTION> --type <FILETYPE> --file <FILENAME>
mongoexport --uri mongodb+srv://<USERNAME>:<PASSWORD>#your-cluster.mongodb.net/<DATABASE_NAME> --collection <COLLECTION> --type <FILETYPE> --out <FILENAME>
You also can found these on Your Cluster > Cmd Line Tools
I am trying to mongoexport a collection named,BrowserHistory from my DB. I have tried doing this through SSH into my CentOS server and a local MongoDB install on my computer. I have MongoDB 2.6 installed.
Note: I have obscured the server, etc. info
The commands I have tried and results are below:
mongoexport --host host.xysz.com:27017 --username iamuser2 --password securepass --db test1ng1 --collection BrowserHistory --out ram.json
Result: "Error parsing command line: too many positional options have
been specified on the command line try 'mongoexport --help' for more
information"
mongoexport --host host.xysz.com:27017 --username iamuser2 --password securepass --db test1ng1 --out ram.json
Result: connected to: host.xysz.com:27017 no collection specified!
Export MongoDB data to CSV, TSV, or JSON files.
I need to output the collection into json file(s) so I can import it into Hive.
Looks like the 'collection' parameter value has whitespace.
This can be overcome by enclosing it in single quote.
mongoexport --host host.xysz.com:27017 --username iamuser2 --password securepass --db test1ng1 --collection 'BrowserHistory' --out ram.json