mongo shell啟動配置文件.mongorc.js(四)
右玉網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)公司從2013年創(chuàng)立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
~/.mongorc.js文件描述如下:
#mongorc.js
===============
我的 mongorc.js 文件.
提供:
- `pretty()` 默認(rèn)使用pretty()幫助方法查詢
- `ugly()` 幫助方法
- prompt 顯示與服務(wù)端類型相關(guān)的信息
## Pretty
mongo shell 有一個幫助函數(shù)叫做 `pretty()` 用于美化結(jié)果集。 使用這個 mongorc.js 文件默認(rèn)啟用pretty行為。
> db.marioGames.find()
{
"_id" : ObjectId("507333d49c25fa3b6e62174d"),
"name" : "Super Mario Bros",
"super" : true,
"release" : ISODate("1985-09-13T07:00:00Z")
}
{
"_id" : ObjectId("5073347b9c25fa3b6e62174e"),
"name" : "Super Mario Bros 2",
"super" : true,
"release" : ISODate("1988-10-09T07:00:00Z")
}
{
"_id" : ObjectId("5073348f9c25fa3b6e62174f"),
"name" : "Super Mario Bros 3",
"super" : true,
"release" : ISODate("1990-02-09T08:00:00Z")
}
## Ugly
現(xiàn)在我們默認(rèn)得到pretty的結(jié)果集合,我們偶爾會需要之前的行為(打印文檔到單行)。
通過使用 `ugly()` 幫助方法。方法:
> db.marioGames({ super: true }).ugly();
{ "_id" : ObjectId("507333d49c25fa3b6e62174d"), "name" : "Super Mario Bros", "super" : true, "release" : ISODate("1985-09-13T07:00:00Z") }
{ "_id" : ObjectId("5073347b9c25fa3b6e62174e"), "name" : "Super Mario Bros 2", "super" : true, "release" : ISODate("1988-10-09T07:00:00Z") }
{ "_id" : ObjectId("5073348f9c25fa3b6e62174f"), "name" : "Super Mario Bros 3", "super" : true, "release" : ISODate("1990-02-09T08:00:00Z") }
## Prompt
默認(rèn)的prompt現(xiàn)在顯示與連接的服務(wù)端相關(guān)的信息。
####replSet
```
replSetName:ServerState|database>
```
####mongos
```
mongos|host:port|database>
```
####mongod
```
mongod|host:port|database>
```
## Installation
git clone git@github.com:aheckmann/mongorc.js.git
cd mongorc.js
make install
它拷貝 .mongorc.js 文件到你的HOME路徑主目錄。
如果另一個 .mongorc.js 文件已經(jīng)存在,它會被重命名為 .mongorc.js.old
## Uninstall
cd mongorc.js
make uninstall
如果 ~/.mongorc.js.old 存在,它將重命名為 ~/.mongorc.js
## Licence
MIT
~/.mongorc.js文件內(nèi)容如下:
;(function () { /** * Make all queries pretty print by default. */ DBQuery.prototype._prettyShell = true /** * Allow opting into the default ugly print mode. */ DBQuery.prototype.ugly = function () { this._prettyShell = false; return this } /** * Override the default prompt to display info related * to type of server we connected to. * * @return {String} */ prompt = function () { var res = rs.status(); if (!res || res.errmsg) { // not in a replica set var status = db.serverStatus(); return status.process + "|" + status.host + "|" + db + "> "; } return replsetPrompt(); } /** * Creates a prompt string for replSets * * @return {String} */ function replsetPrompt () { var status; var admin = db.getSiblingDB("admin"); var info = admin.runCommand({ replSetGetStatus: 1, forShell: 1}); if (info.ok) { var state = ""; // do we need this? info.members.some(function (member) { if (member.self) { state = member.stateStr; return true; } }); status = info.set + ":" + (state || info.myState); } else if (info.info && info.info.length < 20) { // < 20 seems like a hack ?? status = info.info; } return status + "|" + db + "> " } })();
參見:https://github.com/aheckmann/mongorc.js
網(wǎng)頁題目:mongoshell啟動配置文件.mongorc.js(四)
網(wǎng)站地址:http://bm7419.com/article16/pcisdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、、網(wǎng)站營銷、Google、面包屑導(dǎo)航、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)