From 4450a67a7669d5548ad265bb0d1d2b5b47a98d37 Mon Sep 17 00:00:00 2001 From: Pierric Cistac Date: Tue, 20 Aug 2019 16:26:53 -0400 Subject: [PATCH] fix `partial` handling in update --- app/src/app/pages/explore/explore.component.ts | 2 +- lib/Collection.ts | 5 ++++- routes/api.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/app/pages/explore/explore.component.ts b/app/src/app/pages/explore/explore.component.ts index 4b9525f..df258a9 100644 --- a/app/src/app/pages/explore/explore.component.ts +++ b/app/src/app/pages/explore/explore.component.ts @@ -132,7 +132,7 @@ export class ExploreComponent implements OnInit { } editDocument(_id, json) { - const partial = this.params.project && Object.keys(this.params.project).length > 0; + const partial = this.params.project && Object.keys(this.jsonParser.parse(this.params.project)).length > 0; const newId = json && json._id && json._id.$value; const oldId = _id && _id.$value; if (newId !== oldId) { diff --git a/lib/Collection.ts b/lib/Collection.ts index a6575ff..01f9feb 100644 --- a/lib/Collection.ts +++ b/lib/Collection.ts @@ -49,10 +49,13 @@ export class Collection { async updateOne(document: string, newObj: any, partial: boolean) { const newValue = JsonEncoder.decode(newObj); - const update = partial ? {'$set':newValue} : JsonEncoder.decode(newValue); + + // TODO: For now it makes it impossible to remove fields from object with a projection + const update = partial ? { '$set':newValue } : JsonEncoder.decode(newValue); await this._collection.replaceOne({ _id: new MongoDb.ObjectId(document) }, update); + return JsonEncoder.encode(newValue); } diff --git a/routes/api.ts b/routes/api.ts index 418516d..81521aa 100644 --- a/routes/api.ts +++ b/routes/api.ts @@ -91,7 +91,7 @@ api.post('/servers/:server/databases/:database/collections/:collection/documents const database = req.params.database; const collection = req.params.collection; const document = req.params.document; - const partial = !! req.query.partial; + const partial = req.query.partial === 'true'; try { const c = await factory.mongoManager.getCollection(server, database, collection);