You can export data from MongoDB to CSV using the `mongoexport` tool. This tool works on the command line and allows you to export your MongoDB data into JSON or CSV format. Here’s an example of how to do this:
1. Open a command prompt or terminal.
2. Change directory to where your MongoDB’s bin folder is located. For example:
\`\`\`
cd C:\Program Files\MongoDB\Server\3.2\bin
\`\`\`
1. Run the `mongoexport` command with the `-d` flag for specifying the database name, `-c` for the collection name, `—type=csv` to specify the output format and `-o` to specify the output file. For example: \`\`\` mongoexport —host=hostname —port=portnumber —db=dbname —collection=collectionname —type=csv —out=path_to_file.csv \`\`\`
1. In case your collection has a specific set of fields that you want to export, you can use the `-f` or `—fields` option: \`\`\` mongoexport —db=dbname —collection=collectionname —type=csv —fields=field1,field2 —out=path_to_file.csv \`\`\`
Replace `hostname`, `portnumber`, `dbname`, `collectionname`, `path_to_file.csv`, and `field1, field2…` with your own MongoDB connection info, database name, collection name, the path where you want to save your CSV file, and the specific fields you want to export respectively.
Remember that `mongoexport` is a simple tool, best suited for exporting small amount of data. For exporting large datasets, complex queries, or doing heavy data processing, using `mongodump` and `mongorestore` might be more suited.