mongoose-sort-encrypted-field
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -158,6 +158,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
console.time("mongoose-sort-encrypted-field -> generateSortIdForAllDocuments() -> timeTaken: "); | ||
const patients = yield model.find({}, { [fieldName]: 1 }).exec(); | ||
patients.sort((a, b) => { | ||
const documents = yield model.find({}, { [fieldName]: 1 }).exec(); | ||
documents.sort((a, b) => { | ||
let aValue = a[fieldName]; | ||
let bValue = b[fieldName]; | ||
if (!aValue && !bValue) | ||
return 0; | ||
if (!aValue) | ||
return 1; | ||
if (!bValue) | ||
return -1; | ||
aValue = ignoreCases ? aValue.toLowerCase() : aValue; | ||
@@ -167,3 +173,3 @@ bValue = ignoreCases ? bValue.toLowerCase() : bValue; | ||
}); | ||
const n = patients.length; | ||
const n = documents.length; | ||
const log2n = Math.round(Math.log2(n)) + 1; | ||
@@ -177,3 +183,3 @@ let diff = new Base2N("".padEnd(50, "\uffff")); | ||
for (let i = 0; i < n; i += 1) { | ||
yield model.updateOne({ _id: patients[i]._id }, { $set: { [sortFieldName]: curr.toString() } }); | ||
yield model.updateOne({ _id: documents[i]._id }, { $set: { [sortFieldName]: curr.toString() } }); | ||
curr = curr.add(diff); | ||
@@ -180,0 +186,0 @@ } |
{ | ||
"name": "mongoose-sort-encrypted-field", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Mongoose plugin to enable sorting on encrypted fields", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -168,6 +168,9 @@ async function documentsBinarySearch(model, fieldName, fieldValue, sortFieldName, ignoreCases) { | ||
console.time("mongoose-sort-encrypted-field -> generateSortIdForAllDocuments() -> timeTaken: "); | ||
const patients = await model.find({}, { [fieldName]: 1 }).exec(); | ||
patients.sort((a, b) => { | ||
const documents = await model.find({}, { [fieldName]: 1 }).exec(); | ||
documents.sort((a, b) => { | ||
let aValue = a[fieldName]; | ||
let bValue = b[fieldName]; | ||
if (!aValue && !bValue) return 0; | ||
if (!aValue) return 1; | ||
if (!bValue) return -1; | ||
aValue = ignoreCases ? aValue.toLowerCase() : aValue; | ||
@@ -177,3 +180,3 @@ bValue = ignoreCases ? bValue.toLowerCase() : bValue; | ||
}); | ||
const n = patients.length; | ||
const n = documents.length; | ||
const log2n = Math.round(Math.log2(n)) + 1; | ||
@@ -187,3 +190,3 @@ let diff = new Base2N("".padEnd(50, "\uffff")); | ||
for (let i = 0; i < n; i += 1) { | ||
await model.updateOne({ _id: patients[i]._id }, { $set: { [sortFieldName]: curr.toString() } }); | ||
await model.updateOne({ _id: documents[i]._id }, { $set: { [sortFieldName]: curr.toString() } }); | ||
curr = curr.add(diff); | ||
@@ -190,0 +193,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48300
997