MongoDB 匯出和匯入命令的使用

來源:互聯網
上載者:User

Mongodb提供了簡單易用的匯出和匯入命令。

一、匯出命令的簡介與使用。

       MongoDB提供了一個簡單的匯出工具,這個工具位於{MongoDB_HOME}/bin/mongoexport.exe,如(我的mongodb部署在windows作業系統中,在linux中類似):

下面介紹一下如何使用mongoexport匯出命令:mongoexport -c gis -d local -o likehua.data

其中-c  表示幾何  

-d  表示資料庫

-o  輸出檔案名。

更多參數詳見:

Administrator@F523540 d:/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
  --authenticationDatabase arg          user source (defaults to dbname)
  --authenticationMechanism arg (=MONGODB-CR)
                                        authentication mechanism
  --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                      each db is in a separate directly
                                        (relevant only if dbpath specified)
  --journal                             enable journaling (relevant only if
                                        dbpath specified)
  -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
  --forceTableScan                      force a table scan (do not use
                                        $snapshot)

 

二、匯入命令的簡介與使用。

       匯入命令的位置,

使用:

dministrator@F523540 d:/Mongodb/bin
 mongoimport -d local -c gis  --type json --file likehua.data  -f username,_id

--type   匯入的資料的資料類型

--file     匯入的資料的檔案名稱

-f          匯入的欄位

關於匯入命令的更多參數說明如下:

Administrator@F523540 d:/Mongodb/bin
$ mongoimport --help
Import CSV, TSV or JSON data into MongoDB.

When importing JSON documents, each document must be a separate line of the inpu
t file.

Example:
  mongoimport --host myhost --db my_cms --collection docs < mydocfile.json

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
  --authenticationDatabase arg          user source (defaults to dbname)
  --authenticationMechanism arg (=MONGODB-CR)
                                        authentication mechanism
  --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                      each db is in a separate directly
                                        (relevant only if dbpath specified)
  --journal                             enable journaling (relevant only if
                                        dbpath specified)
  -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                          first line in input file is a header
                                        (CSV and TSV only)
  --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 16MB.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.