diff options
author | bob <bcz@cs.brown.edu> | 2019-04-03 11:45:15 -0400 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-04-03 11:45:15 -0400 |
commit | bb7d5a26ec68f283c5adb42d4d6554253de7176f (patch) | |
tree | 7efa817102ba54e916601611f608dd4bd761a437 /src/server/database.ts | |
parent | 43a0768690caa89c606dd5d296d3cc8825c1702b (diff) | |
parent | c406c8d123ce0aa9d63fb8a4dd90adfe83d2889d (diff) |
merged with master
Diffstat (limited to 'src/server/database.ts')
-rw-r--r-- | src/server/database.ts | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/server/database.ts b/src/server/database.ts index 07c5819ab..a42d29aac 100644 --- a/src/server/database.ts +++ b/src/server/database.ts @@ -16,11 +16,20 @@ export class Database { }) } - public update(id: string, value: any) { + public update(id: string, value: any, callback: () => void) { if (this.db) { let collection = this.db.collection('documents'); - collection.update({ _id: id }, { $set: value }, { + collection.updateOne({ _id: id }, { $set: value }, { upsert: true + }, (err, res) => { + if (err) { + console.log(err.message); + console.log(err.errmsg); + } + if (res) { + console.log(JSON.stringify(res.result)); + } + callback() }); } } @@ -32,11 +41,13 @@ export class Database { } } - public deleteAll() { - if (this.db) { - let collection = this.db.collection('documents'); - collection.deleteMany({}); - } + public deleteAll(collectionName: string = 'documents'): Promise<any> { + return new Promise(res => { + if (this.db) { + let collection = this.db.collection(collectionName); + collection.deleteMany({}, res); + } + }) } public insert(kvpairs: any) { @@ -70,6 +81,10 @@ export class Database { let collection = this.db.collection('documents'); let cursor = collection.find({ _id: { "$in": ids } }) cursor.toArray((err, docs) => { + if (err) { + console.log(err.message); + console.log(err.errmsg); + } fn(docs); }) }; |