Skip to content

Commit 2a29ff6

Browse files
authored
Merge pull request #29 from oslabs-beta/james/MongoFix
James/mongo fix
2 parents f676d32 + 048e28f commit 2a29ff6

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

electron/routes/data.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ ipcMain.on('healthRequest', async (message: Electron.IpcMainEvent, service: stri
136136
if (currentDatabaseType === 'MongoDB') {
137137
result = await mongoFetch(service);
138138
}
139+
139140

140141
// SQL Database
141142
if (currentDatabaseType === 'SQL') {
@@ -225,7 +226,7 @@ ipcMain.on('kafkaRequest', async (message) => {
225226
console.log("in kafkaRequest electron!!")
226227
// Mongo Database
227228
if (currentDatabaseType === 'MongoDB') {
228-
229+
result = await mongoFetch('kafkametrics');
229230
}
230231
// SQL Database
231232
if (currentDatabaseType === 'SQL') {

electron/routes/dataHelpers.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ const aggregator = [
1313
output: {
1414
rowNumber: {
1515
$documentNumber: {},
16-
window: ['unbounded', 'current'],
16+
// window: ['unbounded', 'current'],
1717
},
1818
},
1919
},
20+
},
21+
{
2022
$match: {
2123
rowNumber: { $lte: 50 },
2224
},
@@ -27,10 +29,14 @@ const aggregator = [
2729
// Create an aggregator based on the aggregator variable
2830
// return the result
2931
fetchData.mongoFetch = async function (serviceName) {
30-
const testModel = HealthModelFunc(serviceName);
31-
let result = await testModel.aggregate(aggregator);
32-
result = [{ [serviceName]: result }];
33-
return result;
32+
try {
33+
const testModel = HealthModelFunc(serviceName);
34+
let result = await testModel.aggregate(aggregator);
35+
result = [{ [serviceName]: result }];
36+
return result;
37+
} catch (error) {
38+
console.log('Aggregation error in mongoFetch(): ', error);
39+
}
3440
};
3541

3642
fetchData.postgresFetch = async function (serviceName, pool) {
@@ -53,12 +59,11 @@ fetchData.postgresFetch = async function (serviceName, pool) {
5359
;`;
5460

5561
let result = await pool.query(query);
56-
console.log("result.rows in dataHelpers postgresFetch:", JSON.stringify(result.rows));
62+
console.log('result.rows in dataHelpers postgresFetch:', JSON.stringify(result.rows));
5763
result = result.rows;
5864
result = [{ [serviceName]: result }];
59-
console.log("result with servicename in dataHelpers postgresFetch:", JSON.stringify(result));
65+
console.log('result with servicename in dataHelpers postgresFetch:', JSON.stringify(result));
6066
return result;
6167
};
6268

6369
export { fetchData };
64-

0 commit comments

Comments
 (0)