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.
Related
The problem: I need to import a csv file to a mongodb, but i need to specify the field types and still use the --headline cause in my csv the first line is where the fieldnames are.
Here is what i'm tryin:
mongoimport --type csv -d solution2 -c data --headerline --drop dados.csv direction.int32\(\),latitude.double\(\),longitude.double\(\),metrictimestamp.date\(\),odometer.int32\(\),routecode.int32\(\),speed.int32\(\),device_deviceid.int32\(\),vehicle_vehicleid.int32\(\) --columnsHaveTypes
"solution2" is the DB name, "data" is the collection and "dados.csv" is my archive.
I'm getting this error message: Error validating settings: only one positional argument is allowed.
I'm trying to insert the TWDS1E1.json file into mongodb through the command prompt:
db.collections.insert( TWDS1E1.json )
But getting the error:
TWDS1E1.json is not defined.
Mongo is not my thing, what am I doing wrong here?
In command prompt whose directory path is the path where mongoimport.exe is available type the commands
For normal JSON
mongoimport -d test -c docs --file example2.json
For array type JSON
mongoimport --jsonArray -d test -c docs --file example2.json
Please see docs for more information
You cannot use the collection.insert() command to insert a file.
insert() is used to insert actual objects, e.g.
db.myCollection.insert({"name":"buzz"});
To bulk load a JSON file, use mongoimport
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?
When I try to import my json data file into my local instance of mongodb, I get an error. The code that I am using is shown below.
> mongoimport --db cities --collection zips --type json --file C:/MongoDB/data/zips.json
This is the error that I get.
2014-11-29T20:27:33.803-0800 SyntaxError: Unexpected identifier
what seems to be to problem here?
I just found out that mongoimport is used from terminal/command line(cmd), and NOT within the mongo shell.
I am getting an error after executing this command:
mongoexport --db records --collection source_list --csv --out C:\bcopy.csv
record is my DB n source_list is my collection
It displays this message:
assertion: 9998 you need to specify fields
I also tried to specify fields but it is giving me the same error.
What changes should i make in the command to get a backup of my collection or is there any other way to do so ?
Here's sample command that specifies fields to export:
mongoexport -h 127.0.0.1 --port 27018 --db mydb --collection system.profile --csv --out profile.csv --fields ns,millis,numYield,nscanned
In my case --headerline helped. I had around 60 columns, enumerating them with -f would be quite cumbersome.
--headerline
If using “--type csv” or “--type tsv,” use the first line as field names. Otherwise, > mongoimport will import the first line as a distinct document.
Seems like you should be using -f paramater to choose the fields that will be exported to csv file. There is a bug reported for this case to change the explanation as the error message is not informative enough.
https://jira.mongodb.org/browse/SERVER-4224