Skip to content

Commit

Permalink
refactor: replace logic to update mongo views (#439)
Browse files Browse the repository at this point in the history
* refactor: replace logic to update mongo views

* chore: update CHANGELOG
  • Loading branch information
danibix95 authored Jan 10, 2025
1 parent 0d49c56 commit a4f314f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions lib/loadModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4f314f

Please sign in to comment.