-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathby-query.js
More file actions
184 lines (143 loc) · 4.47 KB
/
by-query.js
File metadata and controls
184 lines (143 loc) · 4.47 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// mongodb file
use dcit
// might be best to have two report options, one that goes by Equipment, the other by System and make the route use those. This gets the match list down as quickly as possible
// also, I should be able to add this new report as it is ready to the variouse types I want to run
var reqQuery = {
system: {
systemName: 'apache',
//systemEnviron: 'ri5',
systemRole: 'ui',
},
equip: {
equipLocation: '_',
//equipLocation: 'rsys-dc02',
//equipMake: 'oracle',
},
};
function buildRegex(rQ) {
return Object.keys(rQ).reduce(function(previous, current) {
previous[current] = {'$regex': rQ[current], '$options': 'i'};
return previous;
}, {});
};
function buildRegex2(rQ) {
return Object.keys(rQ).reduce(function(previous, current) {
if(current.indexOf('system') === -1)
previous[current] = {'$regex': rQ[current], '$options': 'i'};
return previous;
}, {});
};
var sysSearch = {};
sysSearch = buildRegex(reqQuery.system);
var eqpSearch = {
equip: {
equip: {},
},
};
eqpSearch.equip = buildRegex2(reqQuery.equip);
print(tojson(eqpSearch));
var findThis = '_';
var inEnv = 'ri2';
db.systemdbs.aggregate([
{$match: sysSearch},
{$lookup:
{ from: 'equipment',
localField: 'systemEquipSN',
foreignField: 'equipSN',
as: 'equip',
},
},
// {$match: eqpSearch},
{$match:
{ 'equip.equipLocation': { '$regex': 'rsys-dc01', '$options': 'i'},
},
},
// {$match:
// { $or: [
// {'equip.equipStatus': 'In Service'},
// {'equip.equipStatus': 'In Service with issues'},
// ]},
// },
/* {$match:
{ 'systemEnviron': inEnv},
}, */
// {$group:
// {
// _id: { env: '$systemEnviron', sysEnv: '$systemEnviron', sysRole: '$systemRole'},
// countApp: {$sum: { $cond: [{$eq: [ '$systemStatus', 'Production App' ]}, 1, 0]}},
// countDb: {$sum: { $cond: [{$eq: [ '$systemStatus', 'Production DB' ]}, 1, 0]}},
// },
// },
// {$sort:
// {
// '_id.env': 1,
// 'countApp': -1,
// 'countDb': -1,
// },
// },
// { $project:
// {
// '_id': 0,
// 'env': '$_id.env',
// 'role': '$_id.sysRole',
// 'countApp': '$countApp',
// 'countDb': '$countDb',
// },
// },
{$limit: 1},
]).pretty()
// this actually works
// var matchKey1 = 'systemName';
// var matchVal1 = 'apache';
// var matchKey2 = 'systemEnviron';
// var matchVal2 = 'ri5';
// match1[matchKey1] = {'$regex': matchVal1, '$options': 'i'};
// match1[matchKey2] = {'$regex': matchVal2, '$options': 'i'};
// var reqQuery = {
// systemName: 'apache',
// //systemEnviron: 'ri5',
// systemRole: 'ui',
// equip: {
// equipLocation: 'rsys-dc01'
// },
// };
// var sysSearch = Object.keys(reqQuery).reduce(function(previous, current) {
// if(current.indexOf('equip') === -1)
// previous[current] = {'$regex': reqQuery[current], '$options': 'i'};
// return previous;
// }, {});
// var eqpSearch = {};
// working
// var rQSys = reqQuery.system;
// //print(tojson(rQSys));
// var sysSearch = Object.keys(rQSys).reduce(function(previous, current) {
// // if(current.indexOf('equip') === -1)
// previous[current] = {'$regex': rQSys[current], '$options': 'i'};
// return previous;
// }, {});
// eqpSearch.equip = buildRegex(rQEqp);
// eqpSearch.equip = Object.keys(rQEqp).reduce(function(previous, current) {
// // if(current.indexOf('equip') === -1)
// previous[current] = {'$regex': rQEqp[current], '$options': 'i'};
// return previous;
// }, {});
//print(tojson(eqpSearch));
// var eqpSearch = {};
// var eqpSearch = Object.keys(reqQuery).reduce(function(previous, current) {
// if(current.indexOf('system') === -1)
// previous[current] = {
// Object.keys(current).reduce(function(previous1, current1) {
// previous1[current1] = {'$regex': reqQuery[current1], '$options': 'i'};
// return previous1;
// };
// return previous;
// }, {});
// eqpSearch.equip = Object.keys(reqQuery.equip).reduce(function(previous, current) {
// if(current.indexOf('system') === -1)
// previous[current] = {'$regex': reqQuery[current], '$options': 'i'};
// return previous;
// }, {});
//var match1 = {};
//var match2 = {};
//match1 = sysSearch;
//match2 = eqpSearch;