非关系型数据库(Nosql)之mongodb:创建集合,备份与导入导出, 数据还原,导入导出(二)

2014-11-24 16:02:02 · 作者: · 浏览: 5
db.dropUser(username)

db.repairDatabase()

db.resetError()

db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into { cmdObj

: 1 }

db.serverStatus()

db.setProfilingLevel(level,) 0=off 1=slow 2=all

db.setWriteConcern( ) - sets the write concern for writes to the db

db.unsetWriteConcern( ) - unsets the write concern for writes to the db

db.setVerboseShell(flag) display extra information in shell output

db.shutdownServer()

db.stats()

db.version() current version of the server

> db.dropDatabase();

{ "dropped" : "toto", "ok" : 1 }

>

\

\

8 数据还原

mongorestore -h localhost:27017 -d toto -directoryperdb F:/beifeng/toto

-h:MongoDB所在服务器地址,例如:127.0.0.1,当然也可以指定端口号:127.0.0.1:27017

-d:需要备份的数据库实例,例如test

-o:备份的数据存放位置,当然该目录需要提前建立,在备份完成后,系统自动在dump目录下建立一个test目录,这个目录里面存放数据库实例的备份数据。

C:\Users\to-to> mongorestore -h localhost:27017 -d toto -directoryperdb F:/beifeng/toto

connected to: localhost:27017

2014-10-15T23:19:11.071+0800 F:/beifeng/toto\c3.bson

2014-10-15T23:19:11.071+0800 going into namespace [toto.c3]

2014-10-15T23:19:14.009+0800 Progress: 5740200/54000000 10% (bytes)

2014-10-15T23:19:17.010+0800 Progress: 10125000/54000000 18% (bytes)

2014-10-15T23:19:20.010+0800 Progress: 15660000/54000000 29% (bytes)

2014-10-15T23:19:23.011+0800 Progress: 22528800/54000000 41% (bytes)

2014-10-15T23:19:26.013+0800 Progress: 29586600/54000000 54% (bytes)

2014-10-15T23:19:29.013+0800 Progress: 36752400/54000000 68% (bytes)

2014-10-15T23:19:32.000+0800 Progress: 43372800/54000000 80% (bytes)

2014-10-15T23:19:35.001+0800 Progress: 50284800/54000000 93% (bytes)

1000000 objects found

2014-10-15T23:19:36.579+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "toto.c3" }

2014-10-15T23:19:36.641+0800 Creating index: { unique: true, key: { age: 1 }, name: "age_1", ns:

"toto.c3" }

2014-10-15T23:19:41.440+0800 F:/beifeng/toto\cap1.bson

2014-10-15T23:19:41.440+0800 going into namespace [toto.cap1]

2014-10-15T23:19:41.440+0800 Created collection toto.cap1 with options: { "create" : "cap1", "cap

ped" : true, "size" : 4096, "max" : 100 }

53 objects found

2014-10-15T23:19:41.440+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "toto.cap1" }

2014-10-15T23:19:41.440+0800 F:/beifeng/toto\cap2.bson

2014-10-15T23:19:41.440+0800 going into namespace [toto.cap2]

2014-10-15T23:19:41.440+0800 Created collection toto.cap2 with options: { "create" : "cap2", "cap

ped" : true, "size" : 4096, "max" : 100 }

file F:/beifeng/toto\cap2.bson empty, skipping

2014-10-15T23:19:41.456+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "toto.cap2" }

C:\Users\to-to>

\

9 导入导出:

用到的应用mongoexport,mongoimport

mongoexport –h dhost –d dbname –c collectionName –o output

参数说明:

-h 数据库地址

-d 指明使用的库

-c 指明要导出的集合

-o 指明要导出的文件名

dname:表示要导出的数据库

collectionName:表示导出哪个集合

output:表示导出到的位置。

C:\Users\to-to>mongoexport -h localhost:27017 -d toto -c c3 -o f:/beifen/c3.txt

connected to: localhost:27017

exported 1000000 records

C:\Users\to-to>

\

\

\

同样可以数据导出到doc

数据导入:

mong