Add option to retreive _id from DB
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
b32c34fe7d
commit
085e6aa80d
@ -13,12 +13,14 @@ const { MongoClient } = require('mongodb');
|
||||
const client = new MongoClient(uri);
|
||||
const db = client.db(dbName);
|
||||
|
||||
async function query(collection, query){
|
||||
async function query(collection, query, returnId = false){
|
||||
await client.connect();
|
||||
log.out(`dbAccess.query: Connecting to collection: '${collection}'`, 'info');
|
||||
var qcoll = db.collection(collection);
|
||||
var qcursor = qcoll.find(query);
|
||||
qcursor.project({_id: 0});
|
||||
if (!returnId) {
|
||||
qcursor.project({_id: 0});
|
||||
}
|
||||
log.out(`dbAccess.query: Running Query: ${JSON.stringify(query)}`, 'info');
|
||||
increment(collection);
|
||||
return (await qcursor.toArray());
|
||||
|
Loading…
Reference in New Issue
Block a user