
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
mongoose-sort-encrypted-field
Advanced tools
Mongoose plugin to enable sorting on encrypted fields
npm i mongoose-sort-encrypted-field
We are having user with encrypted email, We just need to add sortFieldName
option to that field
const { encrypt, decrypt } = require('./encryption.js');
const {
sortEncryptedFields,
evaluateMissedSortFields,
} = require('mongoose-sort-encrypted-field');
const userSchema = new mongoose.Schema({
email: {
type: String,
required: true,
unique: true,
set: encrypt,
get: decrypt,
sortFieldName: 'emailSort',
},
});
userSchema.plugin(sortEncryptedFields);
const User = mongoose.model('User', userSchema);
// Sometimes some field could be missed
// Due to server crash or anything
// So, handling those.
evaluateMissedSortFields(User);
module.exports = User;
Then we can sort all records by email from 'emailSort' field. For proformace we can create mongoDB index for that field.
const sortedUsers = await User.find({}).sort({ emailSort: 1 }).exec();
We create a sort order ID which is just a number in base 2^16, which is huge number system as compared to 10 base number system. We search in DB similar way to binary search but dividing the records into 100 parts intead of 2 parts in binary search. It generate sort order ID in O(1).
Sort order generation is asynchronous using mongoose post middlewares.
FAQs
Mongoose plugin to enable sorting on encrypted fields
The npm package mongoose-sort-encrypted-field receives a total of 12 weekly downloads. As such, mongoose-sort-encrypted-field popularity was classified as not popular.
We found that mongoose-sort-encrypted-field demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.