newStaffLDB-API #48

Merged
fred.boniface merged 85 commits from newStaffLDB-API into main 2023-10-03 21:35:03 +01:00
Showing only changes of commit 1805040f93 - Show all commits

View File

@ -14,9 +14,7 @@ const db = client.db(dbName);
async function query(collection, query, returnId = false) { async function query(collection, query, returnId = false) {
await client.connect(); await client.connect();
logger.trace( logger.trace(`dbAccess.query: Connecting to collection: '${collection}'`);
`dbAccess.query: Connecting to collection: '${collection}'`
);
var qcoll = db.collection(collection); var qcoll = db.collection(collection);
var qcursor = qcoll.find(query); var qcursor = qcoll.find(query);
if (!returnId) { if (!returnId) {
@ -34,7 +32,10 @@ async function queryProject(collection, query, projection) {
logger.debug(`dbAccess.queryProject: Connecting to col: '${collection}'`); logger.debug(`dbAccess.queryProject: Connecting to col: '${collection}'`);
const qcoll = db.collection(collection); const qcoll = db.collection(collection);
const qcursor = qcoll.find(query).project(projection); const qcursor = qcoll.find(query).project(projection);
logger.debug(projection, `dbAccess.query: Running Query: ${JSON.stringify(query)}`) logger.debug(
projection,
`dbAccess.query: Running Query: ${JSON.stringify(query)}`
);
increment(collection); increment(collection);
return await qcursor.toArray(); return await qcursor.toArray();
} }
@ -48,9 +49,7 @@ async function queryAggregate(collection, pipeline) {
} }
async function increment(target) { async function increment(target) {
logger.debug( logger.debug(`dbAccess.increment: Incrementing counter for: ${target}`);
`dbAccess.increment: Incrementing counter for: ${target}`
);
await client.connect(); await client.connect();
let col = db.collection("meta"); let col = db.collection("meta");
let update = {}; let update = {};
@ -102,7 +101,9 @@ async function delRegReq(uuid) {
} }
async function colCount(collection) { async function colCount(collection) {
logger.debug(`dbAccess.colCount: Counting entries in collection: ${collection}`); logger.debug(
`dbAccess.colCount: Counting entries in collection: ${collection}`
);
await client.connect(); await client.connect();
let col = db.collection(collection); let col = db.collection(collection);
let count = col.countDocuments(); let count = col.countDocuments();