2
2
@module MongoHelper
3
3
*/
4
4
5
- import { MongoClient , Db , Collection } from 'mongodb' ;
5
+ import { MongoClient , Db } from 'mongodb' ;
6
6
import { GenericObject } from '../types/types' ;
7
7
8
8
/**
@@ -33,7 +33,7 @@ let db: Db;
33
33
* Get a mongo database object
34
34
* @returns Mongo database object
35
35
*/
36
- async function getDB ( ) : Promise < Db > {
36
+ async function getDB ( ) {
37
37
// if not connected yet, initiate connection
38
38
if ( ! db ) {
39
39
await client . connect ( ) ;
@@ -51,7 +51,7 @@ async function getDB(): Promise<Db> {
51
51
* @param collectionName Name of collection to retreive
52
52
* @returns Mongo collection object
53
53
*/
54
- async function getCollection ( collectionName : string ) : Promise < Collection < GenericObject > > {
54
+ async function getCollection ( collectionName : string ) {
55
55
const db = await getDB ( ) ;
56
56
return db . collection ( collectionName ) ;
57
57
}
@@ -62,7 +62,7 @@ async function getCollection(collectionName: string): Promise<Collection<Generic
62
62
* @param id ID of the document
63
63
* @returns True if document ID exists in the given collection
64
64
*/
65
- async function containsID ( collectionName : string , id : string ) : Promise < boolean > {
65
+ async function containsID ( collectionName : string , id : string ) {
66
66
const collection = await getCollection ( collectionName ) ;
67
67
return ( await collection . countDocuments ( { _id : id } ) ) > 0 ;
68
68
}
@@ -73,7 +73,7 @@ async function containsID(collectionName: string, id: string): Promise<boolean>
73
73
* @param document Document object to add
74
74
* @returns Promise that is resolved when document is added
75
75
*/
76
- async function addDocument ( collectionName : string , document : GenericObject ) : Promise < void > {
76
+ async function addDocument ( collectionName : string , document : GenericObject ) {
77
77
const collection = await getCollection ( collectionName ) ;
78
78
collection . insertOne ( document ) ;
79
79
}
0 commit comments