-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.mongorc.js
72 lines (63 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
try {
// Find the location of .mongorc.js (and therefore then the home directory).
if (typeof(_homedir) === "undefined") {
try {
throw(new Error(""));
} catch (e) {
s = (e.stack);
//print(s); // debug
var _homedir = s.replace(/(.|\n)*(at |@)(.*)\.mongorc\.js:[0-9]+:[0-9]+(.|\n)*$/, "$3");
}
}
if (typeof(_mongorcjs) === "undefined") {
var _mongorcjs = _homedir + ".mongorc\.js";
}
if (typeof(_mongorcd) === "undefined") {
var _mongorcd = _homedir + ".mongorc\.d";
}
allfiles = [];
try {
allfiles = ls(_mongorcd);
} catch (e) {
}
numLoaded = 0;
numFailed = 0;
allfiles.sort().forEach(function (file) {
if (file.endsWith(".js")) {
if (_verboseShell) { // Bit pointless, because this isn't set by "mongo --verbose" like you'd expect
print("Loading " + file + "...");
}
var success = undefined;
try {
success = load(file);
} catch (e) {
success = e;
}
if (success == true) {
numLoaded++;
} else {
numFailed++;
if (typeof(success) == "undefined") {
// Shouldn't happen, no extra info to print, at any rate
print("*** Error loading " + file + ", continuing anyway ***");
} else if (success == false) {
// wut?
print("*** Error loading " + file + ", continuing anyway ***");
} else {
print(success.stack);
}
}
}
});
if ( _verboseShell || ! __quiet && numFailed > 0) {
print("Loaded", numLoaded, (numFailed > 0 ? "(" + numFailed.toString() + " failed) " : "") + "files from", _mongorcd);
}
} catch (e) {
print(e.stack);
print("*** Error loading .mongorc.js, continuing anyway ***");
}
// Don't leak temporary variables
delete s;
delete numLoaded;
delete numFailed;
delete allfiles;