Skip to content

Commit

Permalink
updateMany repo helper - fixes classes.repo.integration.test
Browse files Browse the repository at this point in the history
TODO Check this https://mongoosejs.com/docs/6.x/docs/api/query.html#query_Query-updateMany
the given example references nModified, so why must we change it to modifiedCount?
  • Loading branch information
virgilchiriac committed Nov 22, 2023
1 parent 4277a2e commit d5e620d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/helper/repo.helper.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const { error } = require('../../logger');

/**
* Converts an mongoose update many result to an internal TO
* TODO Check this https://mongoosejs.com/docs/6.x/docs/api/query.html#query_Query-updateMany
* the given example references nModified, so why must we change it to modifiedCount?
*
*
* * Converts an mongoose update many result to an internal TO
* @param {*} param0
* @param {1|0} param0.ok 0 for error
* @param {Integer} param0.n Number of elements matched the given filter
* @param {Integer} param0.nModified Number of elements updated
* @param {Integer} param0.modifiedCount Number of elements updated
*/
const updateManyResult = ({ ok, n, nModified }) => {
const updateManyResult = ({ ok, n, modifiedCount }) => {
if (ok !== 1) {
error('mongoose updateMany has failed', { ok, n, nModified });
error('mongoose updateMany has failed', { ok, n, modifiedCount });
}
return { success: ok === 1, modifiedDocuments: nModified };
return { success: ok === 1, modifiedDocuments: modifiedCount };
};

/**
Expand Down

0 comments on commit d5e620d

Please sign in to comment.