MongoDB备份与恢复(2)—数据导入mongoimport


  • 註冊用戶

    1、概述

    • Mongodb中mongoimport命令可以把指定的格式文件导入到指定的集合中,既可以导入JSON格式数据也可以导入CSV格式数据。

    2、帮助命令-help

    • 可以使用help命令查看Mongoimport的帮助信息,命令操作如下:
    <code>[root@ggtest1 ~]# mongoimport --help
    Usage:
      mongoimport <options> <file>
    Import CSV, TSV or JSON data into MongoDB. If no file is provided, mongoimport reads from stdin.
    See http://docs.mongodb.org/manual/reference/program/mongoimport/ for more information.
    general options:
          --help                                      print usage
          --version                                   print the tool version and exit
    verbosity options:
      -v, --verbose=<level>                           more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or
                                                      specify a numeric value, e.g. --verbose=N)
          --quiet                                     hide all log output
    connection options:
      -h, --host=<hostname>                           mongodb host to connect to (setname/host1,host2 for replica sets)
          --port=<port>                               server port (can also use --host hostname:port)
    kerberos options:
          --gssapiServiceName=<service-name>          service name to use when authenticating using GSSAPI/Kerberos ('mongodb' by default)
          --gssapiHostName=<host-name>                hostname to use when authenticating using GSSAPI/Kerberos (remote server's address by
                                                      default)
    ssl options:
          --ssl                                       connect to a mongod or mongos that has ssl enabled
          --sslCAFile=<filename>                      the .pem file containing the root certificate chain from the certificate authority
          --sslPEMKeyFile=<filename>                  the .pem file containing the certificate and key
          --sslPEMKeyPassword=<password>              the password to decrypt the sslPEMKeyFile, if necessary
          --sslCRLFile=<filename>                     the .pem file containing the certificate revocation list
          --sslAllowInvalidCertificates               bypass the validation for server certificates
          --sslAllowInvalidHostnames                  bypass the validation for server name
          --sslFIPSMode                               use FIPS mode of the installed openssl library
    authentication options:
      -u, --username=<username>                       username for authentication
      -p, --password=<password>                       password for authentication
          --authenticationDatabase=<database-name>    database that holds the user's credentials
          --authenticationMechanism=<mechanism>       authentication mechanism to use
    namespace options:
      -d, --db=<database-name>                        database to use
      -c, --collection=<collection-name>              collection to use
    input options:
      -f, --fields=<field>[,<field>]*                 comma separated list of field names, e.g. -f name,age
          --fieldFile=<filename>                      file with field names - 1 per line
          --file=<filename>                           file to import from; if not specified, stdin is used
          --headerline                                use first line in input source as the field list (CSV and TSV only)
          --jsonArray                                 treat input source as a JSON array
          --type=<type>                               input format to import: json, csv, or tsv (defaults to 'json')
    ingest options:
          --drop                                      drop collection before inserting documents
          --ignoreBlanks                              ignore fields with empty values in CSV and TSV
          --maintainInsertionOrder                    insert documents in the order of their appearance in the input source
      -j, --numInsertionWorkers=<number>              number of insert operations to run concurrently (defaults to 1)
          --stopOnError                               stop importing at first insert/upsert error
          --upsert                                    insert or update objects that already exist
          --upsertFields=<field>[,<field>]*           comma-separated fields for the query part of the upsert
          --writeConcern=<write-concern-specifier>    write concern options e.g. --writeConcern majority, --writeConcern '{w: 3, wtimeout: 500,
                                                      fsync: true, j: true}' (defaults to 'majority')
          --bypassDocumentValidation                  bypass document validation
    [root@ggtest1 ~]#
    </code>

    本帖部分内容已隐藏,请登入并回覆,以查看隐藏内容!


  • 註冊用戶

    最近在匯入 csv 檔案,很實用~ 收藏~


  • 註冊用戶

    想請問一下,並沒有指定欄位的分隔符號是用‘,‘或是tab區隔?

    另外經常遇到的一個問題就是在特定的資料可能會有某個欄位的資料跟分隔符號相同

    此時的情況是整個批次作業會完成.但是把哪筆資料排除

    還是說整個批次作業會取消

    或者是就停在出錯的哪筆資料不往下進行匯入

    如果是最後一種.是否會紀錄匯入到哪筆資料?


  • 註冊用戶

    @neo

    在這篇有討論過,基本上就是要先對文件內容做字串處理,再使用 mongoimport 匯入

    http://forum.foxera.com/mongodb/topic/467/mongodb怎样导入固定分隔符文本文件内容


  • 註冊用戶

    helloworld mongodb


  • Lv 1

    open it soon


登录后回复
 

与 萌阔论坛 的连接断开,我们正在尝试重连,请耐心等待