improve field deletion in collection (#6823)

* added filter to updateMany when deleting field

* added test cases

* added changelog entry
This commit is contained in:
Manuel
2020-07-27 02:22:04 +02:00
committed by GitHub
parent 9ba9620bdf
commit 5b71993175
3 changed files with 44 additions and 1 deletions

View File

@@ -433,6 +433,11 @@ export class MongoStorageAdapter implements StorageAdapter {
collectionUpdate['$unset'][name] = null;
});
const collectionFilter = { $or: [] };
mongoFormatNames.forEach(name => {
collectionFilter['$or'].push({ [name]: { $exists: true } });
});
const schemaUpdate = { $unset: {} };
fieldNames.forEach((name) => {
schemaUpdate['$unset'][name] = null;
@@ -440,7 +445,7 @@ export class MongoStorageAdapter implements StorageAdapter {
});
return this._adaptiveCollection(className)
.then((collection) => collection.updateMany({}, collectionUpdate))
.then((collection) => collection.updateMany(collectionFilter, collectionUpdate))
.then(() => this._schemaCollection())
.then((schemaCollection) =>
schemaCollection.updateSchema(className, schemaUpdate)