mongodb-數據的導入


1、遠程連接 和 本地連接  ./mongo 

根據mongo  --help 可查看mongo的常用命令;
./mongo  172.16.8.189:27017/fashy  連接遠程機器27017端口的fashy庫。
 
./mongo --host 172.16.8.189  --port 27017  fashy  連接遠程機器27017端口的fashy庫
 
 
>exit 可以退出到dos窗口。
 
2、基於MongoDB支持的javascript實現遠程連接
當你已經連接到一個遠程的MongoDB數據庫服務器(例如,通過mongo連接到192.168.0.184),現在想要在這個會話中連接另一個遠程的數據庫服務器(192.168.0.197),可以執行如下命令:
上述通過MongoDB提供的JavaScript腳本,實現對另一個遠程數據庫服務器進行連接,操作指定數據庫fashy的orderInfo集合。
啟動了安全認證模式,可以在獲取數據庫的時候添加上認證。
3、mongodb導入數據的命令mongoimport
中的命令mongoimport -h 172.16.8.189 -d fashy -c orderInfo --type csv --file E:\mongodate\1202.csv --headerline --upsert

-d    指定把數據導入到哪一個數據庫中

-c    指定把數據導入到哪一個集合中

--type    指定導入的數據類型

--file       指定從哪一個文件中導入數據

--headerline    僅適用於導入csv,tsv格式的數據,表示文件中的第一行作為數據頭

--upsert  以新增或者更新的方式來導入數據


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 16MB.

 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM