-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (54 loc) · 1.85 KB
/
index.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
var MongoClient = require('mongodb').MongoClient;
var MONGODB_URI = "";
let cachedDb = null;
var main = function () {
// connectToDatabase(MONGODB_URI)
// .then(db => queryDatabase(db))
// //.then(result => sendCw(result))
// .then(result => {
// console.log('=> returning result: ', result);
// Promise.resolve(result);
// //callback(null, result.length);
// })
// .catch(err => {
// console.log('=> an error occurred: ', err);
// //callback(err);
// });
let totalSingleCareNumbers;
MongoClient.connect(MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true }, function (err, db) {
if (err) {
console.error('An error occurred connecting to the database: ' + err);
process.exit(1);
} else {
console.log('=> query database');
let dbString = "";
if (process.env.ENVIRONMENT == 'stage'){
dbString = 'Fetch_V2_Staging';
}
else if (process.env.ENVIRONMENT == 'prod'){
dbString = 'Fetch_V2_Production';
} else {
dbString = 'Fetch_V2_Dev';
}
console.log('=======> connecting to ' + dbString);
var db2 = db.db(dbString);
console.log('=======> running query');
var x = db2.collection('UserSingleCareNumber').countDocuments({"assignedDate":{$exists:false}},{}, function (err, docCount) {
if (err) {
console.log('Error in countDocuments '+ err);
return null;
}
if (docCount) {
console.log('The number of Sc numbers is ' + docCount);
totalSingleCareNumbers = docCount;
db.close();
}
});
console.log('At bottom of countDocument x is ' + x);
}
});
return totalSingleCareNumbers;
}
if (require.main === module) {
main()
}