當前位置:首頁 » 數據倉庫 » mongovue導出資料庫
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

mongovue導出資料庫

發布時間: 2022-12-11 21:45:49

Ⅰ mongodb資料庫集合導入導出(遷移)

導出:mongoexport -h IP --port PORT -u USERNAME -p PASSWORD -d DATABASE -c COLLECTION --type=json -o /home/area.json

導入:mongoimport -h IP --port PORT -u USERNAME -p PASSWORD -d DATABASE -c COLLECTION --type=json --file area.json

Ⅱ mongomp導出數據時資料庫里是否能查看到記錄

mongodb數據備份和還原主要分為二種,一種是針對於庫的mongomp和mongorestore,一種是針對庫中表的mongoexport和mongoimport。
一,mongomp備份資料庫

1,常用命令格

?1 mongomp -h IP --port 埠 -u 用戶名 -p 密碼 -d 資料庫 -o 文件存在路徑

如果沒有用戶誰,可以去掉-u和-p。
如果導出本機的資料庫,可以去掉-h。
如果是默認埠,可以去掉--port。
如果想導出所有資料庫,可以去掉-d。

Ⅲ mongodb用mongoexport命令導出數據為什麼一直顯示百分之零

一、導出工具mongoexport
Mongodb中的mongoexport工具可以把一個collection導出成JSON格式或CSV格式的文件。可以通過參數指定導出的數據項,也可以根據指定的條件導出數據。mongoexport具體用法如下所示:
Shell代碼
[root@localhost mongodb]# ./bin/mongoexport --help
Export MongoDB data to CSV, TSV or JSON files.

options:
--help proce 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
參數說明:
-h:指明資料庫宿主機的IP
-u:指明資料庫的用戶名
-p:指明資料庫的密碼
-d:指明資料庫的名字
-c:指明collection的名字
-f:指明要導出那些列
-o:指明到要導出的文件名
-q:指明導出數據的過濾條件

實例:test庫中存在著一個students集合,集合中數據如下:
Js代碼
> db.students.find()
{ "_id" : ObjectId("5031143350f2481577ea81e5"), "classid" : 1, "age" : 20, "name" : "kobe" }
{ "_id" : ObjectId("5031144a50f2481577ea81e6"), "classid" : 1, "age" : 23, "name" : "nash" }
{ "_id" : ObjectId("5031145a50f2481577ea81e7"), "classid" : 2, "age" : 18, "name" : "james" }
{ "_id" : ObjectId("5031146a50f2481577ea81e8"), "classid" : 2, "age" : 19, "name" : "wade" }
{ "_id" : ObjectId("5031147450f2481577ea81e9"), "classid" : 2, "age" : 19, "name" : "bosh" }
{ "_id" : ObjectId("5031148650f2481577ea81ea"), "classid" : 2, "age" : 25, "name" : "allen" }
{ "_id" : ObjectId("5031149b50f2481577ea81eb"), "classid" : 1, "age" : 19, "name" : "howard" }
{ "_id" : ObjectId("503114a750f2481577ea81ec"), "classid" : 1, "age" : 22, "name" : "paul" }
{ "_id" : ObjectId("503114cd50f2481577ea81ed"), "classid" : 2, "age" : 24, "name" : "shane" }
由上可以看出文檔中存在著3個欄位:classid、age、name
1.直接導出數據到文件中
Shell代碼
[root@localhost mongodb]# ./bin/mongoexport -d test -c students -o students.dat
connected to: 127.0.0.1
exported 9 records
命令執行完後使用ll命令查看,發現目錄下生成了一個students.dat的文件
Shell代碼
-rw-r--r-- 1 root root 869 Aug 21 00:05 students.dat
查看該文件信息,具體信息如下:
Shell代碼
[root@localhost mongodb]# cat students.dat
{ "_id" : { "$oid" : "5031143350f2481577ea81e5" }, "classid" : 1, "age" : 20, "name" : "kobe" }
{ "_id" : { "$oid" : "5031144a50f2481577ea81e6" }, "classid" : 1, "age" : 23, "name" : "nash" }
{ "_id" : { "$oid" : "5031145a50f2481577ea81e7" }, "classid" : 2, "age" : 18, "name" : "james" }
{ "_id" : { "$oid" : "5031146a50f2481577ea81e8" }, "classid" : 2, "age" : 19, "name" : "wade" }
{ "_id" : { "$oid" : "5031147450f2481577ea81e9" }, "classid" : 2, "age" : 19, "name" : "bosh" }
{ "_id" : { "$oid" : "5031148650f2481577ea81ea" }, "classid" : 2, "age" : 25, "name" : "allen" }
{ "_id" : { "$oid" : "5031149b50f2481577ea81eb" }, "classid" : 1, "age" : 19, "name" : "howard" }
{ "_id" : { "$oid" : "503114a750f2481577ea81ec" }, "classid" : 1, "age" : 22, "name" : "paul" }
{ "_id" : { "$oid" : "503114cd50f2481577ea81ed" }, "classid" : 2, "age" : 24, "name" : "shane" }
參數說明:
-d:指明使用的庫,本例中為test
-c:指明要導出的集合,本例中為students
-o:指明要導出的文件名,本例中為students.dat
從上面的結果可以看出,我們在導出數據時沒有顯示指定導出樣式 ,默認導出了JSON格式的數據。如果我們需要導出CSV格式的數據,則需要使用--csv參數,具體如下所示:
Shell代碼
[root@localhost mongodb]# ./bin/mongoexport -d test -c students --csv -f classid,name,age -o students_csv.dat
connected to: 127.0.0.1
exported 9 records
[root@localhost mongodb]# cat students_csv.dat
classid,name,age
1.0,"kobe",20.0
1.0,"nash",23.0
2.0,"james",18.0
2.0,"wade",19.0
2.0,"bosh",19.0
2.0,"allen",25.0
1.0,"howard",19.0
1.0,"paul",22.0
2.0,"shane",24.0
[root@localhost mongodb]#
參數說明:
-csv:指明要導出為csv格式
-f:指明需要導出classid、name、age這3列的數據
由上面結果可以看出,mongoexport成功地將數據根據csv格式導出到了students_csv.dat文件中。

二、導入工具mongoimport
Mongodb中的mongoimport工具可以把一個特定格式文件中的內容導入到指定的collection中。該工具可以導入JSON格式數據,也可以導入CSV格式數據。具體使用如下所示:
Shell代碼
[root@localhost mongodb]# ./bin/mongoimport --help
options:
--help proce 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.
參數說明:
-h:指明資料庫宿主機的IP
-u:指明資料庫的用戶名
-p:指明資料庫的密碼
-d:指明資料庫的名字
-c:指明collection的名字
-f:指明要導入那些列

示例:先刪除students中的數據,並驗證
Js代碼
> db.students.remove()
> db.students.find()
>
然後再導入上面導出的students.dat文件中的內容
Shell代碼
[root@localhost mongodb]# ./bin/mongoimport -d test -c students students.dat
connected to: 127.0.0.1
imported 9 objects
[root@localhost mongodb]#
參數說明:
-d:指明資料庫名,本例中為test
-c:指明collection名,本例中為students
students.dat:導入的文件名
查詢students集合中的數據
Js代碼
> db.students.find()
{ "_id" : ObjectId("5031143350f2481577ea81e5"), "classid" : 1, "age" : 20, "name" : "kobe" }
{ "_id" : ObjectId("5031144a50f2481577ea81e6"), "classid" : 1, "age" : 23, "name" : "nash" }
{ "_id" : ObjectId("5031145a50f2481577ea81e7"), "classid" : 2, "age" : 18, "name" : "james" }
{ "_id" : ObjectId("5031146a50f2481577ea81e8"), "classid" : 2, "age" : 19, "name" : "wade" }
{ "_id" : ObjectId("5031147450f2481577ea81e9"), "classid" : 2, "age" : 19, "name" : "bosh" }
{ "_id" : ObjectId("5031148650f2481577ea81ea"), "classid" : 2, "age" : 25, "name" : "allen" }
{ "_id" : ObjectId("5031149b50f2481577ea81eb"), "classid" : 1, "age" : 19, "name" : "howard" }
{ "_id" : ObjectId("503114a750f2481577ea81ec"), "classid" : 1, "age" : 22, "name" : "paul" }
{ "_id" : ObjectId("503114cd50f2481577ea81ed"), "classid" : 2, "age" : 24, "name" : "shane" }
>
證明數據導入成功
上面演示的是導入JSON格式的文件中的內容,如果要導入CSV格式文件中的內容,則需要通過--type參數指定導入格式,具體如下所示:
先刪除數據
Js代碼
> db.students.remove()
> db.students.find()
>
再導入之前導出的students_csv.dat文件

Shell代碼
[root@localhost mongodb]# ./bin/mongoimport -d test -c students --type csv --headerline --file students_csv.dat
connected to: 127.0.0.1
imported 10 objects
[root@localhost mongodb]#
參數說明:
-type:指明要導入的文件格式
-headerline:指明第一行是列名,不需要導入
-file:指明要導入的文件
查詢students集合,驗證導入是否成功:

Js代碼
> db.students.find()
{ "_id" : ObjectId("503266029355c632cd118ad8"), "classid" : 1, "name" : "kobe", "age" : 20 }
{ "_id" : ObjectId("503266029355c632cd118ad9"), "classid" : 1, "name" : "nash", "age" : 23 }
{ "_id" : ObjectId("503266029355c632cd118ada"), "classid" : 2, "name" : "james", "age" : 18 }
{ "_id" : ObjectId("503266029355c632cd118adb"), "classid" : 2, "name" : "wade", "age" : 19 }
{ "_id" : ObjectId("503266029355c632cd118adc"), "classid" : 2, "name" : "bosh", "age" : 19 }
{ "_id" : ObjectId("503266029355c632cd118add"), "classid" : 2, "name" : "allen", "age" : 25 }
{ "_id" : ObjectId("503266029355c632cd118ade"), "classid" : 1, "name" : "howard", "age" : 19 }
{ "_id" : ObjectId("503266029355c632cd118adf"), "classid" : 1, "name" : "paul", "age" : 22 }
{ "_id" : ObjectId("503266029355c632cd118ae0"), "classid" : 2, "name" : "shane", "age" : 24 }
>

Ⅳ mongodb資料庫怎麼導出數據

用mongodb自帶工具 mongoexport,在bin目錄下輸入:mongoexport --help點擊回車可以看到Export MongoDB data to CSV, TSV or JSON files.這樣的信息,根據相關參數可以導出成csv的文件

Ⅳ idea的mongo插件把線上的資料庫怎麼導到本地

本機是Windows 7 32位,故下載的是mongodb-win32-i386-2.6.1.zip,後續常式均是基於該版本資料庫。

2、配置環境變數

解壓mongodb-win32-i386-2.6.1.zip文件到E:\,並重新命名mongodb-win32-i386-2.6.1文件夾為mongodb,目錄結構如下圖

並在系統設置中配置環境變數path = E:\mongodb\bin;( 便於在命令行中直接使用mogodb命令 )

3、配置MongoDB資料庫

創建一個mongo.config配置文件,配置MongoDB資料庫的dbpath(資料庫存儲路徑)和logpath(日誌文件存儲路徑);

你也可是使用 --dbpath選項和 --logpath選項來配置路徑;
##store data here
dbpath=E:\mongodb\data

##all output go here
logpath=E:\mongodb\log\mongo.log
特別提示:

由於dbpath路徑為 E:\mongodb\data ,而這個文件夾默認不存在,故 需手動創建 ,不然在執行MongoDB伺服器時會提示找不到該文件夾;同理,也需 手動創建 一個 E:\mongodb\log 文件夾用於保存日誌。

4、啟動MongoDB伺服器

使用 mongod.exe --config E:\mongodb\mongo.config 啟動MongoDB伺服器。--config 選項表示啟動時通過 E:\mongodb\mongo.config配置文件的信息配置伺服器。

5、連接MongoDB伺服器

使用mongo.exe連接已經啟動的MongoDB server。(如果第4步伺服器沒有啟動成功,連接MongoDB伺服器時會報第7步異常里的錯誤!)

啟動成功後,進入mongodb shell命令行,在 mongodb shell命令行 中我們可以進行資料庫的訪問,已經對資料庫執行CRUD操作。

6、添加MongoDB到Winodows服務

window服務來啟動MongoDB 伺服器。其實做到第5步,我們已經完成了對MongoDB數據的安裝已經配置,可以直接開始鼓搗MongoDB CRUD命令

了,但是每次都通過第4步進行添加配置並啟動難免麻煩,這才有了第6步添加MongoDB到window服務,實現了通過啟動服務來啟動MongoDB 服務

器。

1)添加MongoDB到Windows Service, 以便於通過window服務配置系統啟動時MongoDB服務自動啟動。配置成功後,在控制面板的服務中可看到該服務,如下所示:

C:\Users\Administrator> mongod --config D:\mongodb\mongo.config --install

2)啟動MongoDB服務

C:\Users\Administrator> net start MongoDB

3)停止MongoDB服務

C:\Users\Administrator> net stop MongoDB

4)從windows服務中移除MongoDB服務

C:\Users\Administrator> mongod --remove

5)通過mongod --help查看更多的配置命令選項。

C:\Users\Administrator> mongod --help

--install install mongodb service
--remove remove mongodb service
7、異常:

warning: Failed to connect to 127.0.0.1:27017, reason: errno:10061

表示:沒有啟動MondoDB伺服器,或啟動伺服器失敗;

Ⅵ robomongo 怎麼導出數據

robomongo 導出數據步驟如下:

1、啟動Mongodb資料庫。在自己電腦的E盤、D盤根目錄模擬出兩個Mongodb的資料庫,分別代表舊庫和新庫。

Ⅶ mongoDB怎麼把數據導出為csv或excel

1、打開命令行,進入我們所安裝的MongoDB路徑下的bin文件夾
2、我們採用bin文件夾下的mongoexport方法進行導出,

mongoexport -d myDB -c user -f _id,name,password,adress --csv -o ./user.csv

-d 標示 資料庫
-c 標示 數據表
-f 需要提取的field用逗號分隔
-o 輸出路徑

Ⅷ 使用rockmongo怎麼導出部分數據

數據導出:先舉個例子作為切入口:
需求:
將test資料庫下的things集合中的所有文檔導出到D:\mongo_data路徑下
D:\mongo\bin>mongoexport -d test -c things -o d:\mongo_data\things.txt
cmd控制台返回導出的相關信息,如下所示
connected to: 127.0.0.1
exported 15 records
檢驗一下:
去D:\mongo_data找一下是否存在things.txt文件
打開D:\mongo_data\things.txt顯示如下:
{ "_id" : 3 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55de" }, "x" : 6, "y" : 0 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55df" }, "x" : 6, "y" : 1 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e0" }, "x" : 6, "y" : 2 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e1" }, "x" : 6, "y" : 3 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e2" }, "add" : [ { "age" : 21, "name" : "jimvin" }, { "age" : 22, "name" : "jimvin" }, { "age" : 23, "name" : "jimvin" }, { "age" : 23, "name" : "jimvin" } ], "x" : 6, "y" : 4 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e3" }, "num" : 55, "x" : 6, "y" : 5 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e4" }, "age" : null, "num" : null, "x" : 6, "y" : 6 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e5" }, "add" : [ "jimvin", "abc", "aaa" ], "num" : "abc", "x" : 6, "y" : 7 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e6" }, "age" : [ 7, 9 ], "name" : "jimvin", "num" : 20, "x" : 6, "y" : 8 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e7" }, "age" : [ 7, 8, 9 ], "name" : "tom", "x" : 10, "y" : 9 }
{ "_id" : { "$oid" : "5296e6d68378a9afba69af46" }, "add" : { "age" : 20, "name" : "jimvin" }, "name" : "jim", "num" : 10 }
{ "_id" : { "$oid" : "529eab9552bf5eb74acdb35b" }, "name" : "person1", "addr" : { "city" : "a", "state" : "d" } }
{ "_id" : { "$oid" : "529eaba252bf5eb74acdb35c" }, "name" : "person1", "addr" : { "city" : "b", "state" : "c" } }
{ "_id" : { "$oid" : "529eabc352bf5eb74acdb35d" }, "name" : "person1", "addr" : { "city" : "a", "state" : "e" } }

從例子我們基本都能猜出 mongoexport的命令用法,下面我們再詳細分析一下:
* mongoexport --db
簡寫 mongoexport -d
指定要導出集合所在的資料庫
eg:
D:\mongo\bin>mongoexport --db test
或 D:\mongo\bin>mongoexport -d test
或 D:\mongo\bin>mongoexport -db test
注意:
1. 不能單獨使用,至少還要指定集合才能導出成功。
否則顯示如下錯誤:
no collection specified!
2. 假如指定的資料庫名在MongoDB中是不存在的,也不會報錯的。
* mongoexport --collection
簡寫 mongoexport -c
指定要導出集合的名字
eg:
D:\mongo\bin>mongoexport --collection test
或 D:\mongo\bin>mongoexport -c test
或 D:\mongo\bin>mongoexport -collection test

注意:
這里是可以正常運行起來的,這里MongoDB系統在沒指定資料庫來源時,默認從test數據 庫找相應的集合的,然後把對應的文檔輸出到cmd控制台上,假如我們指定的集合名在test資料庫是不存在的,也不會報錯,只是返回「exported 0 records」這樣的提示。
* mongoexport --out
簡寫 mongoexport -o
指定導出數據文件的目錄
eg:
D:\mongo\bin>mongoexport --out d:\mongo_data\things.txt
或 D:\mongo\bin>mongoexport -o d:\mongo_data\things.txt
或 D:\mongo\bin>mongoexport -out d:\mongo_data\things.txt
注意:
1. 不能單獨使用,至少還要指定集合才能導出成功。
否則顯示如下錯誤:
no collection specified!
2. 文件目錄不能寫成d:\mongo_data或 d:\mongo_data\或d:\之類的,否則報錯如下:
coundn't open [d:\mongo_data]。
一定要帶有文件名的(帶有後綴的),一般為.txt,.csv,.json,.csv
csv和csv文件:都是常用的數據交互格式,均可以用excell打開。
3. 純粹D:\mongo\bin>mongoexport --out d:\mongo_data\things.txt這樣寫,即使我們沒指定集合,但系統依然會為我們創建things.txt這個文件的。
在RockMongo 導出test資料庫mythings集合會是一個js文件:
如下所示:
/** mythings indexes **/
db.getCollection("mythings").ensureIndex({
"_id": NumberInt(1)
},[

]);
/** mythings indexes **/
db.getCollection("mythings").ensureIndex({
"location": 1,
"name": -1
},[

]);
/** mythings records **/
db.getCollection("mythings").insert({
"_id": ObjectId("529fe7faeef00d1d48b473c0"),
"location": "Guangzhou",
"age": 20,
"name": "j"
});
db.getCollection("mythings").insert({
"_id": ObjectId("529fe808eef00d1d48b473c1"),
"location": "Guangzhou",
"age": 21,
"name": "ji"
});
......

最後,再重申一點,所有導出操作,必須保證在資料庫處於正常連接的狀態。否則顯示:couldn't conncect to [127.0.0.1] couldn't connect to server 127.0.0.1:27017

Ⅸ mongovue是什麼 百度百科

MongoVUE是一款針對MongoDB的客戶端工具,現在連接資料庫也叫數據模式有2種方法,一種是B/S結構的資料庫,通過網頁就可以訪問。另外一種就是基於C/S客戶端的連接方式

Ⅹ 如何從MongoDB導入/導出數據

在開始菜單的運行框中輸入dtswiz,然後選擇源數據源和目標數據源,例如:如果是從SQLServer中導出到Excel中,那麼那麼需要在其中輸入SQL語句或者選擇指定資料庫中的一個或多個表,然後再指定Excel的路徑和文件名,如果是從Excel導入到SQLServer中,就簡單一些,選擇好具體的Excel文檔後,再選擇其中的某一個Sheet(工作表),然後再設置SQLServer的指定資料庫即可,還可以從SQLServer中的一個資料庫導入到SQLServer的另一個資料庫中,方法類似