aboutsummaryrefslogtreecommitdiff
path: root/src/server/database.ts
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-07-05 19:32:44 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-07-05 19:32:44 -0400
commit8a902049db8378e13a28b19b1ad34a36882fbcb1 (patch)
tree001a9f94b91d0a946d3ffb59c12fbb27059c4683 /src/server/database.ts
parentb8e41f32eba62a3e569e82e2908f4ff0c1e29f6c (diff)
Added garbage collector
Diffstat (limited to 'src/server/database.ts')
-rw-r--r--src/server/database.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/server/database.ts b/src/server/database.ts
index d240bd909..a17447629 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -41,11 +41,17 @@ export class Database {
}
}
- public delete(id: string, collectionName = Database.DocumentsCollection) {
+ public delete(query: any, collectionName?: string): Promise<mongodb.DeleteWriteOpResultObject>;
+ public delete(id: string, collectionName?: string): Promise<mongodb.DeleteWriteOpResultObject>;
+ public delete(id: any, collectionName = Database.DocumentsCollection) {
+ if (typeof id === "string") {
+ id = { _id: id };
+ }
if (this.db) {
- this.db.collection(collectionName).remove({ id: id });
+ const db = this.db;
+ return new Promise(res => db.collection(collectionName).deleteMany(id, (err, result) => res(result)));
} else {
- this.onConnect.push(() => this.delete(id, collectionName));
+ return new Promise(res => this.onConnect.push(() => res(this.delete(id, collectionName))));
}
}
@@ -125,7 +131,7 @@ export class Database {
return Promise.resolve<mongodb.Cursor>(this.db.collection(collectionName).find(query));
} else {
return new Promise<mongodb.Cursor>(res => {
- this.onConnect.push(() => res(this.query(query)));
+ this.onConnect.push(() => res(this.query(query, collectionName)));
});
}
}