0

I am trying to export a certain set of records. but it errors claiming invalid JSON

mongoexport ... --type=csv --collection users --query '{"role": "Student"}' --out x.csv

error validating settings: query '[123 114 111 108 101 58 32 83 116 117 100 101 110 116 125]' is not valid JSON: invalid character 'S' looking for beginning of value

I dont know where the array of numbers is coming from - and the query is valid JSON

2
  • What is your MongoDB version? Please post the output of mongod --version and mongoexport --version Commented Jun 12, 2019 at 5:41
  • mongodb is ATLAS - Version 4.0.10 mongoexport version: r4.0.4 git version: f288a3bdf201007f3693c58e140056adf8b04839 Go version: go1.8.5 os: windows arch: amd64 compiler: gc OpenSSL version: OpenSSL 1.0.2o-fips 27 Mar 2018 Commented Jun 12, 2019 at 6:46

1 Answer 1

1

This is because Windows doesn't recognize single quotes as a "quote" character. Unlike UNIX, Windows treats single and double quotes differently.

Switch the quotes around and it should work:

mongoexport ... --query "{'role': 'Student'}" ...
Sign up to request clarification or add additional context in comments.

1 Comment

good info - thanks - it worked...the one combo I didn't try because single quotes always kills me in a JSON validator...

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.