【正文】
use ydb switched to db ydb 。(jkfFS$343$_\=\,.F339。shirdrn39。pagedb39。:2701739。 use ydb switched to db ydb db ydb () { _id : ObjectId(4eded6a5bf3bfa0014000003), content : 巴黎是浪漫的城市,可是..., pubdate : 20060319, title : 巴黎:從布魯塞爾趕到巴黎, url : } 上述通過MongoDB提供的JavaScript腳本,實(shí)現(xiàn)對另一個(gè)遠(yuǎn)程數(shù)據(jù)庫服務(wù)器進(jìn)行連接,操作指定數(shù)據(jù)庫pagedb的page集合。pagedb39。:2701739。db address39。 f _id,title,content,images,publishDate,spiderName,url jsonArray 否則,就會(huì)出現(xiàn)下面的錯(cuò)誤:[plain] view plaincopyERROR: too many positional options (六)遠(yuǎn)程連接管理基于mongo實(shí)現(xiàn)遠(yuǎn)程連接[plain] view plaincopymongo u admin p admin :27017/pagedb 通過mongo實(shí)現(xiàn)連接,可以非常靈活的選擇參數(shù)選項(xiàng),參看命令幫助,如下所示:[plain] view plaincopymongo help MongoDB shell version: usage: mongo [options] [db address] [file names (ending in .js)] db address can be: foo foo database on local machine :9999/foo foo database on machine on port 9999 options: shell run the shell after executing files nodb don39。 if not specified, stdout is used jsonArray output to a json array rather than one object per line 注意:如果上面的選項(xiàng)q指定一個(gè)查詢條件,需要使用單引號括起來,如下所示:[plain] view plaincopymongoexport d page c Article q 39。type支持的類型有三個(gè):csv、tsv、json其他各個(gè)選項(xiàng)的使用,可以查看幫助:[plain] view plaincopymongoimport help options: help produce help message v [ verbose ] be more verbose (include multiple times for more verbosity . vvvvv) 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 d [ db ] arg database to use c [ collection ] arg collection to use (some mands) f [ fields ] arg ma separated list of field names . 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。向MongoDB導(dǎo)入數(shù)據(jù)mongoimport d pagedb c page type csv headerline drop 說明:,使用cvs或tsv文件的列名作為集合的列名?;謴?fù)某個(gè)數(shù)據(jù)庫的數(shù)據(jù)cd testbakmongorestore d pagedb drop說明:將備份的pagedb的數(shù)據(jù)恢復(fù)到數(shù)據(jù)庫。備份一個(gè)數(shù)據(jù)庫中的某個(gè)集合mongodump d pagedb c page說明:備份數(shù)據(jù)庫pagedb的page集合。執(zhí)行命令,結(jié)果示例如下:[plain] view plaincopy{ info : now locked against writes, use db.$() to unlock, ok : 1 } 查看當(dāng)前鎖狀態(tài)()說明:查詢結(jié)果如下所示:[plain] view plaincopy{ inprog : [ ], fsyncLock : 1, info : use db.$() to terminate the fsync write/snapshot lock } 其中,fsyncLock為1表示MongoDB的fsync進(jìn)程(負(fù)責(zé)將寫入改變同步到磁盤)不允許其他進(jìn)程執(zhí)行寫數(shù)據(jù)操作解鎖use admindb.$()說明:執(zhí)行解鎖,結(jié)果如下所示:[plain] view plaincopy{ ok : 1, info : unlock requested } 可以執(zhí)行命令查看鎖狀態(tài):()狀態(tài)信息如下:[plain] view plaincopy{ inprog : [ ] } 說明當(dāng)前沒有鎖,可以執(zhí)行寫數(shù)據(jù)操作。添加用戶(admin, ,%F23_kj~00Opoo0+\/)添加數(shù)據(jù)庫用戶,添加成功,則顯示結(jié)果如下所示:[plain] view plaincopy{ user : admin, readOnly : false, pwd : 995d2143e0bf79cba24b58b3e41852cd } 安全認(rèn)證(admin, ,%F23_kj~00Opoo0+\/)數(shù)據(jù)庫安全認(rèn)證。(四)安全管理以安全認(rèn)證模式啟動(dòng)mongod auth dbpath /usr/mongo/data logfile /var/使用auth選項(xiàng)啟動(dòng)mongod進(jìn)程即可啟用認(rèn)證模式。或者執(zhí)行:mongod f /etc/ repair終止服務(wù)器進(jìn)程()終止數(shù)據(jù)庫服務(wù)器進(jìn)程。(三)啟動(dòng)與終止正常啟動(dòng)mongod dbpath /usr/mongo/data logfile /var/