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.

3
  • 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 Commented Dec 21, 2015 at 10:49
  • @SarathNair: Thats spelling mistake. But error I'm facing is same. Commented Dec 21, 2015 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? Commented Dec 21, 2015 at 11:41

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Without any double quotes is sufficient like this --query {'status':'A'} ,because it's receiving json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.