Mongoimport not finding file? - json

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"

Related

Importing Multiple Json Files At Once Into Mongodb

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

How to export data from mongodb to json

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.

import json file into mongodb [ missing ; before statement #<shell> ]

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.

How to import json file to mongo through mac terminal?

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

mongodb-error validating settings: only one positional argument is allowed

I just moved to a new laptop which had mongo 3.0.0 I believe.
On the new laptop I have mongo 3.0.4. and trying the script that was working on the old laptop is giving me errors. This line is giving me the error.
mongoimport --host localhost \
-db roudy123_q \
-collection LebaneseAmericanUniversity\(Lebanon\).json \
--file LebaneseAmericanUniversity\(Lebanon\).json \
--jsonArray
error validating settings: only one positional argument is allowed.
I googled the error and the only relevant result was the source code of mongoimport. So I guess it has something to do with the new version.
Just a wild guess...
... but the various long options should be specified using --, not -:
mongoimport --host localhost \
--db roudy123_q \
--collection LebaneseAmericanUniversity\(Lebanon\).json \
--file LebaneseAmericanUniversity\(Lebanon\).json \
--jsonArray
Maybe this particular version of mongoimport is more punctilious about that, and will treat -db ... -collection ... as positional arguments rather than keyword arguments ?
This error can also occur if white spaces are given without a "\" in the path to the file .
Ex:
This wont work:
But this would work :
If you are getting mongodb-error validating settings: only one positional argument is allowed.
Just put --file path in " ".
2.use / instead of \ in --file path.
Also, put --host in " ".
For example:
Suppose you are trying to import data from your local machine to server (MongoDB Atlas or your MongoDB server or locally) in your collection then follow this:
mongoimport --host "cluster0-shard-00-01-ceax1.mongodb.net:27017" --db <dbname> --type json --file "C:/Users/ranjeet/Downloads/MongoDb project/ranjeet.json" --authenticationDatabase admin --ssl --username <Username> --password <Password> --collection <CollectionName>
If you get this error while inserting fields with --fields, the probable reason might be you are using spaces to do that.
Both -f and --fields should work in those cases
Using Mongo Version 3.0.6
mongoimport --db logs --collection action_logs --type tsv -f updated_at ,transaction_time ,origin --file parsed.tsv
mongoimport --db logs --collection action_logs --type tsv -f updated_at,transaction_time,origin --file parsed.tsv
I think giving a white spaces in the file name of directory will also contribute to this error.
None of the above mentioned answers solved my problem but they indeed helped me in figuring out what I was doing wrong.(I am using windows)
1)using -d instead of --d (shorthand only require one - not two --)
2)using "" for absolute file path.
3)Changing \ to / in file path location.
For example my files location in windows is:
C:\kp github\other projects\projectXyz\myFile.csv
So for me the command that worked was:
mongoimport -d users -c contacts --type=csv --headerline --file="C:/kp github/other projects/projectXyz/myFile.csv" or
mongoimport -d users -c contacts --type csv --headerline --file "C:/kp github/other projects/projectXyz/myFile.csv"
where users is my db name and contacts is my collection name
The below is the correct example of command when your database have user name and password created
mongoimport --host 127.0.0.1
--port 27000
--username XXXXX
--password PPPPP
--authenticationDatabase admin
--db applicationData
--collection products
--file products.json
Please make sure you do not have any extra spaces after
and before -- as well.