why mongoexport behaves this way? - mongodb

when I run this,
mongoexport --db mydb_dev --collection location_updates --csv --fields lat,lon --out location.csv
it gives me,
connected to: 127.0.0.1
exported 0 records
However when I move --db to the end and run this,
mongoexport --collection location_upates --csv --fields lat,lon --out location.csv --db mydb_dev
it gives me,
connected to: 127.0.0.1
exported 92913 records
Any idea why it works like this? Is there ordering of Options important in Mongo?

Related

mongoexport not exporting any record from collection

Whats wrong with my command?? It is shows exported 0 records
mongoexport --host maint5-w:27017 -u harry12 -p harry12 --db MTLINKi --collection PROGRAM_HISTORY --type csv --fields L1NAME,TIMESPAN --out zips.csv

Syntax error:missing ; before statement #(shell):1:15 [duplicate]

I'm working with mongodb 2.4.3 and I cannot get mongoexport to work. The error message I get with each command is:
"JavaScript execution failed: SyntaxError: Unexpected identifier"
At first I thought the problem was with my query parameters, which were long. But find() worked fine with the query so I know that the syntax is ok. I then created a new collection using the query and tried exporting the collection with the following:
mongoexport --db Oct2012 --collection sept8subset --csv --fields "text","created_at","user.screen_name","user.followers_count" --out sept8.csv
mongoexport --db Oct2012 --collection sept8subset --csv --fields text,created_at,user.screen_name,user.followers_count --out sept8.csv
mongoexport -d Oct2012 -c sept8subset --csv --fields text,created_at,user.screen_name -o sept8.csv
mongoexport --db Oct2012 --collection sept8subset --dbpath ~/db (should need dbpath as mongod instance is running)
mongoexport --db OCt2012 -collection sept8subset -o sept8.txt
mongoexport --db Oct2012 --collection sept8subset
In each case, I get "JavaScript execution failed: SyntaxError: Unexpected identifier". Where could that SyntaxError be??
The collection I'm trying to copy has 50,339 objects. In case it is just too big for mongoexport to handle, I took 5 documents out of the collection to make a new collection. I then tried to export them using same command structure as above. I still get the same error message.
Now I'm wondering if the problem is that mongoexport can't work with data involving dates. MongoDB documentation states that I may want to write my own export script using a client driver.
Does anyone have an idea of what my problem is here? Many thanks if you can help out.
I found out that running mongoexport from the mongo client--as I was doing--is incorrect. Mongoexport is executed at the command prompt.
I ran into this too and I solved it executing the command from the path/bin where 'mongoexport' is located.In my case :
my_path: /usr/local/Cellar/mongodb/2.4.4-x86_64/bin
"mongoexport -d book -c shelf"
'mongod' is located one step upper from 'mongoimport' , 'mongoexport', etc...

How to take mongodump for 1 collection from my Database in MongoDB

How to take mongodump for 1 collection from my Database
../mongodump --db db_name --collection collection_name --out /home/dell/999/
i got this error
bash: ../mongodump: No such file or directory
This is working for entire db backup
./mongodump --out /home/dell/777/ --db dbname
But back up for single collection from a database not working
Use mongoexport to export collection data:
mongoexport --db test --collection mycollection --out myCollection.json
If it's a replica set and you want to use the --uri you should use it like this cause documentation states that you can't specify some options when using --uri
mongodump --uri "mongodb://user:password#mongo-en-1.example.io:27017,mongo-en-2.example.io:27017,mongo-en-3.example.io:27017/$Databasename?replicaSet=$replicasetname&authSource=admin" --collection $collectionname

mongoexport --fields --csv will only output the first field when working with subdocuments

Working:
.\mongoexport.exe --db mydb --collection slideproof_user_event_date_count --csv --out
events.csv --fields '_id,first_day'
.\mongoexport.exe --db mydb --collection slideproof_user_event_date_count --out
events.json --fields '_id._p,first_day'
Not working (only first field/column has content) written, :
.\mongoexport.exe --db mydb --collection slideproof_user_event_date_count --csv --out
events.csv --fields '_id._p, first_day'
How can I enable correct output for .csv with subdocument fields?
The solution is to avoid spaces in the --fields argument:
this works:
--fields '_id._p,value.count'
This does not:
--fields '_id._p, value.count'

mongoexport syntax error message

I'm working with mongodb 2.4.3 and I cannot get mongoexport to work. The error message I get with each command is:
"JavaScript execution failed: SyntaxError: Unexpected identifier"
At first I thought the problem was with my query parameters, which were long. But find() worked fine with the query so I know that the syntax is ok. I then created a new collection using the query and tried exporting the collection with the following:
mongoexport --db Oct2012 --collection sept8subset --csv --fields "text","created_at","user.screen_name","user.followers_count" --out sept8.csv
mongoexport --db Oct2012 --collection sept8subset --csv --fields text,created_at,user.screen_name,user.followers_count --out sept8.csv
mongoexport -d Oct2012 -c sept8subset --csv --fields text,created_at,user.screen_name -o sept8.csv
mongoexport --db Oct2012 --collection sept8subset --dbpath ~/db (should need dbpath as mongod instance is running)
mongoexport --db OCt2012 -collection sept8subset -o sept8.txt
mongoexport --db Oct2012 --collection sept8subset
In each case, I get "JavaScript execution failed: SyntaxError: Unexpected identifier". Where could that SyntaxError be??
The collection I'm trying to copy has 50,339 objects. In case it is just too big for mongoexport to handle, I took 5 documents out of the collection to make a new collection. I then tried to export them using same command structure as above. I still get the same error message.
Now I'm wondering if the problem is that mongoexport can't work with data involving dates. MongoDB documentation states that I may want to write my own export script using a client driver.
Does anyone have an idea of what my problem is here? Many thanks if you can help out.
I found out that running mongoexport from the mongo client--as I was doing--is incorrect. Mongoexport is executed at the command prompt.
I ran into this too and I solved it executing the command from the path/bin where 'mongoexport' is located.In my case :
my_path: /usr/local/Cellar/mongodb/2.4.4-x86_64/bin
"mongoexport -d book -c shelf"
'mongod' is located one step upper from 'mongoimport' , 'mongoexport', etc...