Skip to content

Commit

Permalink
fix partial handling in update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierrci authored and n1t0 committed Aug 20, 2019
1 parent 83fe3b4 commit 4450a67
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/app/pages/explore/explore.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion lib/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4450a67

Please sign in to comment.