Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-sort-encrypted-field

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-sort-encrypted-field - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

14

lib/utils.js

@@ -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 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc