1

When I try to take backup with mongoexport using the --query option to get the documents whose status is equal to A, facing the below error:

mongoexport --port 27017 --db ex --collection A --type=csv --fields _id,status --query '{"status":"A"}' -o eg.csv

error validating settings: query ''{status:A}'' is not valid JSON

Please let me know how to use --query option.

Sarath Nair
  • 2,828
  • 2
  • 21
  • 36
Ganu
  • 539
  • 5
  • 12
  • 1
    query looks fine to me. Also there's a typo in query: its fields not fileds. But that wont be related to your original problem – Sarath Nair Dec 21 '15 at 10:49
  • @SarathNair: Thats spelling mistake. But error I'm facing is same. – Ganu Dec 21 '15 at 10:59
  • The same format of command is working for me, can you double check the statement you issued and the one shown here? – Sarath Nair Dec 21 '15 at 11:41

1 Answers1

9

Assuming you run this from the DOS command prompt, you need to swap the single and double quotes. You need to wrap the entire query in double quotes and use single quotes inside the JSON document like this:

--query "{'status':'A'}"

I have tested this with mongoexport version 3.0.0 and 3.2.0 and it works for both versions.

Alex
  • 21,273
  • 10
  • 61
  • 73
  • 1
    Without any double quotes is sufficient like this --query {'status':'A'} ,because it's receiving json – Hamedz Jun 16 '16 at 12:40