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.
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 have a few pairs of bson/json files. I know how to import bson files, but how to do with the json files? Should I import them in a particular order if at all?
You can import JSON files by specifying the type in mongoimport command like this,
mongoimport --db <db name> --collection <collection name> --type json --file example.json --jsonArray
It is the first time I use mongodb.
I want to insert a zip.json file into mongodb running one of the commands bellow, and I get error.
mongoimport --db test --collection zips --file \C:\Install\advanced programs\mongodb\zips.json
mongoimport --db test --collection zips --type json --file \C:\Install\advanced programs\mongodb\zips.json
The error:
To run these commands I oppened a cmd in bin directory of mongodb and I ran mongo.
you should use double quotation "" for file path because your file path contained space and no need to extra back slash \C:\ just use C:\
use
mongoimport --db test --collection zips --file "C:\Install\advanced programs\mongodb\zips.json"
instead of
mongoimport --db test --collection zips --file \C:\Install\advanced programs\mongodb\zips.json
Perhaps your json is not valid? Looks like there is an extra quote somewhere. Try validating it using any online service.
You need to start different cmd and go to C:\Program Files\MongoDB\Server\3.2\bin or it should be in ur path and then u need to run "mongoimport" command. If you start using "mongoimport" from "mongo" shell then it will not work.
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