Too many positional options mongoimport Error - mongodb

I have a comma separated csv file with data for following fields: Train_ID ,Train_Number, Train_name
I wrote the following query to import the data from csv to mongodb:
mongoimport --db test --collection csvimporting --type csv --file "C:/Darshil Babel/Desktop/sample_data.csv" --fields Train_ID,Train_Number,Train_Name
It is giving following error:
Error parsing command line: too many positional options
What am I doing wrong?

Related

mongoimport csv with headerline and datatype

I'm trying to import a csv into mongodb using the following command:
mongoimport --db users --collection contacts --file data.csv
--headerline
The database exists but not the collection, I want to create it and use the first row of the csv as the field names. Why am I getting error:
error validating settings: must specify --fields, --fieldFile or
--headerline to import this file type
I also would like to know:
how to copy/import data from one collection into another (basically
the syntax)
how datatypes from csv are handled in mongodb when
imported; do I need to specify datatypes for headers or will mongodb
read it from csv types?
To solve this:
Either make sure the first line of your data.csv file has field names of the data to be parsed and then execute:
mongoimport --db users --collection contacts --type csv --headerline --file data.csv
Or
Define the list of field names that the values of csv would be parsed in using --fields
mongoimport --db users --collection contacts --type csv --file data.csv --fields["name","surname","etc"]
You should write command like this:
mongoimport --db users --collection contacts --type csv --file data.csv --fields "name","surname","etc"

MongoDB - validating settings error

I'm trying to import a CSV file into MongoDB using the following command;
mongoimport -db results --collection socialogy --type csv --file "F:\Projects\pandas\results.csv" --headerline
MongoDB gives the following error message;
error validating settings: incompatible options: --file and positional argument(s)
What am I doing wrong?
You seem to have typo in your query. See -db option part, it should be --db. This way your really mix arguments as error message says.

Cannot insert into mongo using mongoImport

I am trying to insert a json file into mongo using mongo import
this is my first try:
mongoimport --file someorders.json --type json --db test --collection someorders
I get the following error:
exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0
Then I tried:
mongoimport --file someorders.json --type json --db test --collection someorders --jsonArray
And the I get the following error:
exception:JSONArray file too large
warning: log line attempted (16384k) over max size(10k), printing beginning and end ... {
... prints some of the json
ERROR: encountered 1 error(s)

Failed: line1, column 134: extraneous " in field Error while importing csv file in MongoDb

I'm new to mongodb and while trying to import csv file using the syntax below it returns the error below.The first lines of my csv file is as follows:
Source,"ID","Date","Timestamp","Author","Author ID","Longitude","Latitude","Likes","Comments","Retweets","Text"
Can anyone kindly help me.Thank you in advance ! error output image
C:\Program Files\MongoDB\Server\3.2\bin>mongoimport --db mydatabase
--collection sites --type csv --headerline --file C:\mydata\sample.csv
Output Error
2016-07-06T16:07:51.395+0200 Failed: line 1, column 134:
extraneous " in field
2016-07-06T16:07:51.397+0200 imported 0 documents
It is better Convert CSV file into JSON format
or
import JSON instead of CSV.
To import JSON as collection of objects then
Example:
JSON1 :
[{"project":"project_1","status":"yes","priority":7},{"project":"project_2","status":"yes","priority":7},{"project":"project_3","status":"yes","priority":7}]
mongoimport --db myDB--collection myCollection --file battles.json --jsonArray
Imprort as single object
JSON2 :
[{"mydata":[{"project":"project_1","status":"yes","priority":7},{"project":"project_2","status":"yes","priority":7},{"project":"project_3","status":"yes","priority":7}]}]
mongoimport --db myDB--collection myCollection --file battles.json
Ref:
Failed: error unmarshaling bytes on document #0: JSON decoder out of sync - data changing underfoot?
jsonArray import
error invalid character

MongoDB import error assertion 9998

I seem to keep having this error when i try and import anything?
In terminal I input:
name:~ computer$ mongoimport --db users --collection contacts --type csv --file /Users/computer/Desktop/ftse100.csv
connected to: 127.0.0.1
assertion: 9998 you need to specify fields
I wouldn't know what to ask. I tried adding --field after this command line but just get help information.
ER
As per mongodb docs
--fields <field1[,field2]>, -f
Specify a comma separated list of field names when importing csv or tsv files that do not have field names in the first (i.e. header) line of the file.
mongoimport --db users --collection contacts --type csv --file /Users/computer/Desktop/ftse100.csv --fields field1, field2,field3
As per your question, there is a typo it's not --field instead --fields
In 2.4.6, mongoimport does not find the header in csv files that I make, with or without double quote boundaries.
If I chop off the header line and supply that same text to the -f or --fields option, it my files import fine.
If you want to add all columns, use --headerline option instead of -fields.
In your case it would be:
mongoimport --db users --collection contacts --type csv --headerline --file /Users/computer/Desktop/ftse100.csv