-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmongorc.js
executable file
·34 lines (30 loc) · 936 Bytes
/
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
// generate a MONGO_PS1 DB_STATE#host[dbname]>
(function() {
'use strict';
var states = ['STARTUP', 'PRIMARY', 'SECONDARY', 'RECOVERING', 'FATAL', 'STARTUP2', 'UNKNOWN', 'ARBITER', 'DOWN', 'ROLLBACK'];
var host = typeof db === 'undefined' ? '' : db.serverStatus().host;
prompt = function() {
if (typeof db === 'undefined') {
return '> ';
}
var dbState;
var status = '';
var dbStatus = db.isMaster();
if (dbStatus.setName) {
if (dbStatus.ismaster) {
dbState = 'PRIMARY';
} else if (dbStatus.secondary) {
dbState = 'SECONDARY';
} else {
dbState = states[rs.status().myState];
}
if (dbStatus.hidden) {
dbState = dbState.toLowerCase();
}
status = dbState + ':[' + dbStatus.setName + ']#';
}
return status + host + ' [' + db + ']> ';
};
})();
// always enable pretty print
DBQuery.prototype._prettyShell = true;