diff options
author | bob <bcz@cs.brown.edu> | 2019-07-09 14:18:28 -0400 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-07-09 14:18:28 -0400 |
commit | fb1e2078dc0e0cdc33f6037cd3c3e18ffded413e (patch) | |
tree | ddd2fb40e4e344b3c3b1e0f7057b62566a92084c /src/server/database.ts | |
parent | 724d03b8d05b5ef7ef944c648aae8f43dde625be (diff) | |
parent | ce39600f0c7b9013c7c8ec8c74eb54d2d5e4c50e (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
Diffstat (limited to 'src/server/database.ts')
-rw-r--r-- | src/server/database.ts | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/server/database.ts b/src/server/database.ts index a17447629..29a8ffafa 100644 --- a/src/server/database.ts +++ b/src/server/database.ts @@ -126,12 +126,16 @@ export class Database { } } - public query(query: any, collectionName = "newDocuments"): Promise<mongodb.Cursor> { + public query(query: { [key: string]: any }, projection?: { [key: string]: 0 | 1 }, collectionName = "newDocuments"): Promise<mongodb.Cursor> { if (this.db) { - return Promise.resolve<mongodb.Cursor>(this.db.collection(collectionName).find(query)); + let cursor = this.db.collection(collectionName).find(query); + if (projection) { + cursor = cursor.project(projection); + } + return Promise.resolve<mongodb.Cursor>(cursor); } else { return new Promise<mongodb.Cursor>(res => { - this.onConnect.push(() => res(this.query(query, collectionName))); + this.onConnect.push(() => res(this.query(query, projection, collectionName))); }); } } |