-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongorc.js
49 lines (42 loc) · 1.15 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
load("/Users/shri/.mongohacker.js");
prompt = function () {
let host = db.serverStatus().host.split('.')[0];
host = host.replace(/(-cluster)?-shard-\d+-\d+-\w+$/, "")
return db + '@' + host + '> ';
}
// Pretty print by default.
DBQuery.prototype._prettyShell = true
shellHelper.cs = function () {
const colls = db.runCommand("listCollections");
printjson(colls);
};
/**
* Dump indexes defined in all collections in current database.
*/
function indexDump() {
const indexes = {};
for (const collection of db.getCollectionNames()) {
indexes[collection] = db.getCollection(collection).getIndexes();
}
printjson(indexes);
}
function mongorc() {
load("/Users/shri/.mongorc.js");
}
/**
* Commands for lookup by id.
*/
shellHelper.org = idFinder("organization");
shellHelper.app = idFinder("application");
shellHelper.act = idFinder("newAction");
shellHelper.user = idFinder("user");
shellHelper.pl = idFinder("plugin");
shellHelper.page = idFinder("newPage");
shellHelper.ds = idFinder("datasource");
function idFinder(collectionName) {
return function (id) {
db[collectionName].find({_id: ObjectId(id)}).forEach(doc => {
printjson(doc);
});
};
}