In the bin directory of MongoDB, there is a mongoexport that can be used for data export
[Email protected] bin]$/mongoexport--Helpusage:mongoexport<options>Export Data fromMongodbinchCSV or JSON format. See http://docs.mongodb.org/manual/reference/program/mongoexport/for more information.General Options:--Help Print Usage--version Print the tool version and exitverbosity options:-V,--verbose=<level> more detailed log output (include multiple times forMore verbosity, e.g. -VVVVV, or specify a numeric value, e.g.--verbose=N)--quiet Hide all log outputconnection options:-H,--host= forreplica sets)--port=<port> Server port (can also use--host Hostname:port) SSL options:--SSL Connect to a Mongod or MONGOs this has SSL enabled--sslcafile=<filename> the. pem file containing the root certificate chain fromThe Certificate Authority--sslpemkeyfile=<filename>The . Pem file containing the certificate and key--sslpemkeypassword=<password> the password to decrypt the sslpemkeyfile,ifnecessary--sslcrlfile=<filename>The . Pem file containing the certificate revocation list--sslallowinvalidcertificates Bypass the validation forServer Certificates--sslallowinvalidhostnames Bypass the validation forServer name--Sslfipsmode use FIPS mode of the installed OpenSSL libraryauthentication options:-U,--username=<username> username forAuthentication-P,--password=<password> password forAuthentication--authenticationdatabase=<database-name> database that holds the user's Credentials--authenticationmechanism=<mechanism>authentication mechanism to usenamespaceOptions:-D,--db=<database-name>database to use-C,--collection=<collection-name>collection to Useoutput options:-F,--fields=<field>[,<field>]* Comma separated list of field names (required forExporting CSV) e.g.-F"Name,age"--fieldfile=<filename> file with field names-1per Line--type=<type> the output format, either JSON or CSV (defaults to'JSON') (default: JSON)-O,-- out=<filename> output file;ifNot specified, stdout isused--jsonarray output to a JSON array rather than oneObjectper Line--pretty output JSON formatted to be human-readable--noheaderline export CSV data without a list of field names at the first linequerying Opti ONS:-Q,--query=<json> query filter, asA JSONstring, e.g.,'{x:{$gt: 1}}'--queryfile=<filename>path to a file containing a query filter (JSON)-K,--slaveok allow secondary readsifAvailable (default true) (default:false) --readpreference=<string>|<json> specify either a preference name or a preference JSONObject--forcetablescan Force a table scan ( DoNot use $snapshot)--skip=<count>Number of documents to skip--limit=<count>limit The number of documents to export--sort=<json> sort order, asA JSONstring, e.g.'{x:1}'--assertexistsifspecified, export failsifThe collection does not exist (default: false)
Export the file to JSON:
Export to json:$ mongoexport.exe -D testdb-c testcollection-o ./test.json
Export files to CSV
./mongoexport--csv--o/opt/wenbronk_soft/- 07 -. csv
May appear garbled, save utf-8 with Notepad
When filtering data using the-Q query condition, pay attention to the ' (single quotes) on both sides
When the amount of data is very large, you can use--skip with--limit, limit the amount of data for a single file, easy for ordinary users to view
mongodb-exporting data to a CSV file or JSON file