-
Notifications
You must be signed in to change notification settings - Fork 0
/
.mongorc.js
82 lines (66 loc) · 1.68 KB
/
.mongorc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;(function () {
/**
* Override some potentially dangerous helpers so they are no-ops.
* If needed, restart shell with --norc option.
*/
var no = function() {
print("Not on my watch. Restart shell with --norc option if you want to do this.");
};
// Prevent dropping databases
db.dropDatabase = DB.prototype.dropDatabase = no;
// Prevent dropping collections
DBCollection.prototype.drop = no;
// Prevent dropping indexes
DBCollection.prototype.dropIndex = no;
/**
* 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 + "|" + new Date() + "> ";
}
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 + "> "
}
})();