Search code examples
mongodbcsvmongoexport

mongoexport with a query does not return expected results


im trying to use a regular expression in the query field of mongoexport so i can limit the fields that are not the test emails for running load tests with a test users, email, password, and apiKey.

I was able to use a find with

db.users.find({email:/@company.com/},{apiKey:1,email:1}).pretty()

and this retrieved just the records I wanted, but the following:

mongoexport -d db_dev -c users -f apiKey,email -q "{{email:{/@company.com/}}}" --csv -o usersKeys.csv

does not seem to work for me. Any pointers? Im using mongo2.6.3 on a mac.


Solution

  • sorry guys im a little slow today. got it now:

    mongoexport -d db_dev -c users -f apiKey,email -q "{email:/@company.com/}" --csv -o /Users/kingHenry/Desktop/usersKeys.csv connected to: 127.0.0.1 exported 205 records