mongoimport mongoexport

    xiaoxiao2024-02-18  134

    mongoexport:将数据导出成JSON格式,与标准的JSON有些不同

    参数说明:

    [root@localhost mongodb]# ./bin/mongoexport --help  Export MongoDB data to CSV, TSV or JSON files.    options:    --help                    produce help message    -v [ --verbose ]          be more verbose (include multiple times for more                               verbosity e.g. -vvvvv)    --version                 print the program's version and exit    -h [ --host ] arg         mongo host to connect to ( <set name>/s1,s2 for                               sets)    --port arg                server port. Can also use --host hostname:port    --ipv6                    enable IPv6 support (disabled by default)    -u [ --username ] arg     username    -p [ --password ] arg     password    --dbpath arg              directly access mongod database files in the given                               path, instead of connecting to a mongod  server -                               needs to lock the data directory, so cannot be used                              if a mongod is currently accessing the same path    --directoryperdb          if dbpath specified, each db is in a separate                               directory    --journal                 enable journaling    -d [ --db ] arg           database to use    -c [ --collection ] arg   collection to use (some commands)    -f [ --fields ] arg       comma separated list of field names e.g. -f                               name,age    --fieldFile arg           file with fields names - 1 per line    -q [ --query ] arg        query filter, as a JSON string    --csv                     export to csv instead of json    -o [ --out ] arg          output file; if not specified, stdout is used    --jsonArray               output to a json array rather than one object per                               line    -k [ --slaveOk ] arg (=1) use secondaries for export if available, default                               true  

    常用: mongoexport -d testdb -c testcol -o out.dat

    mongoimport:从JSON导入,由于与标准的JSON略有些不同,如果出现错误,可以先导出看看mongo的格式要求,再导入

    [root@localhost mongodb]# ./bin/mongoimport --help  options:    --help                  produce help message    -v [ --verbose ]        be more verbose (include multiple times for more                             verbosity e.g. -vvvvv)    --version               print the program's version and exit    -h [ --host ] arg       mongo host to connect to ( <set name>/s1,s2 for sets)    --port arg              server port. Can also use --host hostname:port    --ipv6                  enable IPv6 support (disabled by default)    -u [ --username ] arg   username    -p [ --password ] arg   password    --dbpath arg            directly access mongod database files in the given                             path, instead of connecting to a mongod  server -                             needs to lock the data directory, so cannot be used                             if a mongod is currently accessing the same path    --directoryperdb        if dbpath specified, each db is in a separate                             directory    --journal               enable journaling    -d [ --db ] arg         database to use    -c [ --collection ] arg collection to use (some commands)    -f [ --fields ] arg     comma separated list of field names e.g. -f name,age    --fieldFile arg         file with fields names - 1 per line    --ignoreBlanks          if given, empty fields in csv and tsv will be ignored    --type arg              type of file to import.  default: json (json,csv,tsv)    --file arg              file to import from; if not specified stdin is used    --drop                  drop collection first     --headerline            CSV,TSV only - use first line as headers    --upsert                insert or update objects that already exist    --upsertFields arg      comma-separated fields for the query part of the                             upsert. You should make sure this is indexed    --stopOnError           stop importing at first error rather than continuing    --jsonArray             load a json array, not one item per line. Currently                             limited to 4MB.  

    相关资源:敏捷开发V1.0.pptx
    最新回复(0)