Skip to content

Commit

Permalink
fix(stores/mongodb.ts) fix when try to remove a not existing user
Browse files Browse the repository at this point in the history
  • Loading branch information
rimiti committed May 2, 2019
1 parent a13648f commit 9aa956a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/stores/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class MongoDBStore implements IStore {
this.transaction.push(async () => {
const collection = await this.db.collection(this.prefix + this.removeUnsupportedChar(collName)); // tslint:disable-line no-unsafe-any
// Create index
await collection.ensureIndex({_bucketname: 1, key: 1}); // tslint:disable-line no-unsafe-any
await collection.ensureIndex({ _bucketname: 1, key: 1 }); // tslint:disable-line no-unsafe-any
})
}

Expand All @@ -217,8 +217,8 @@ export class MongoDBStore implements IStore {
*/
public async del(bucket: string, keys: string | string[]): Promise<void> {
const keysParam = MongoDBStore.makeArray(keys);
const updateParams = (this.useSingle? {_bucketname: bucket, key:{$in:keysParam}} : {key:{$in:keysParam}});
const collName = (this.useSingle? aclCollectionName : bucket);
const updateParams = this.useSingle ? { _bucketname: bucket, key: { $in: keysParam } } : { key: { $in: keysParam } };
const collName = this.useSingle ? aclCollectionName : bucket;

this.transaction.push(async () => {
const collection = await this.db.collection(this.prefix + this.removeUnsupportedChar(collName)); // tslint:disable-line no-unsafe-any
Expand All @@ -239,14 +239,18 @@ export class MongoDBStore implements IStore {
const collName = (this.useSingle? aclCollectionName : bucket);

const valuesParam = MongoDBStore.makeArray(values);
if (valuesParam.length === 0) {
return;
}

this.transaction.push(async () => {
const collection = await this.db.collection(this.prefix + this.removeUnsupportedChar(collName)); // tslint:disable-line no-unsafe-any
// build doc from array values
// Build doc from array values
const document = {};
// @ts-ignore
valuesParam.forEach((value: Object) => { document[value]=true; });

// update document
// Update document
await collection.update(updateParams,{ $unset: document },{ safe: true, upsert: true }); // tslint:disable-line no-unsafe-any
});
}
Expand Down

0 comments on commit 9aa956a

Please sign in to comment.