0

I'm trying to export a mongodb query to csv file. here's what I have:

mongoexport --db db_name --collection agents --query ‘{ $and: [ {clients_count: {$gt:2}}, {vendors_count:{$gt:10}} ] }’ --csv --fieldFile userFields.txt --out outputFilePathAndName.csv

I got the following error:

Error parsing command line: too many positional options

What am I doing wrong?

DBWeinstein
  • 8,605
  • 31
  • 73
  • 118
  • Those curly quotes make me wonder. – Nathan Tuggy Apr 16 '15 at 02:57
  • Try changing your quotes. http://stackoverflow.com/questions/25921183/mongoexport-too-many-positional-options – Juan Carlos Farah Apr 16 '15 at 02:57
  • possible duplicate of [What does "too many positional options" mean when doing a mongoexport?](http://stackoverflow.com/questions/7521163/what-does-too-many-positional-options-mean-when-doing-a-mongoexport) – Juan Carlos Farah Apr 16 '15 at 02:59
  • @JuanCarlosFarah thanks, but I'm still not getting it. I only have one set of single quotes. Should each argument also be in quotes? I'm on a Mac if that makes a difference. – DBWeinstein Apr 16 '15 at 03:13
  • Have you tried using straight double quotes? `--query "{ ... }"`? – Juan Carlos Farah Apr 16 '15 at 03:18
  • @JuanCarlosFarah yup. didn't work. – DBWeinstein Apr 16 '15 at 03:57
  • I removed the paces in the query per this post: http://stackoverflow.com/questions/15185238/mongodb-error-on-mongos-too-many-positional-options, but now have another error: `assertion: 16619 code FailedToParse: FailedToParse: Expecting '}' or ',': offset:56 of:{$and:[{clients_count:{$gt:2}},{vendors_count:{$gt:10}}]` – DBWeinstein Apr 16 '15 at 04:02

1 Answers1

0

got it. correct query:

mongoexport --db db_name --collection collectionName --query '{$and:[{clients_count:{$gt:2}},{vendors_count:{$gt:10}}]}' --csv --fieldFile userFields.txt --out filepat/fileName.csv

the key is to use single quotes ' and leave no spaces in the query.

EDIT

having issue with the fields, but seems to be grabbing the correct documents.

DBWeinstein
  • 8,605
  • 31
  • 73
  • 118