From a4f314fc331fde0e6431cd8e251d69dad0f2acda Mon Sep 17 00:00:00 2001 From: Daniele Bissoli Date: Fri, 10 Jan 2025 10:47:47 +0100 Subject: [PATCH] refactor: replace logic to update mongo views (#439) * refactor: replace logic to update mongo views * chore: update CHANGELOG --- CHANGELOG.md | 4 ++++ lib/loadModels.js | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d64228e..684f0833 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- overhauled Mongo view update logic to avoid requesting [`dropCollection`](https://www.mongodb.com/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection) privilege action + ## 7.2.2 - 2024-12-13 ### Changed diff --git a/lib/loadModels.js b/lib/loadModels.js index 0f862220..6fcfab47 100644 --- a/lib/loadModels.js +++ b/lib/loadModels.js @@ -162,11 +162,13 @@ function collectionModelMapper( ) } + // in case a view with selected name already exists, update it with the newer configuration if (existingCollections.includes(collectionName)) { - await mongoInstance - .db - .collection(collectionName) - .drop() + return mongoInstance.db.command({ + collMod: collectionName, + viewOn: viewSourceCollectionName, + pipeline, + }) } return mongoInstance