
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
mongoose-find-by-whatever
Advanced tools
Creates a find query based on the value you are trying to find by. I mostly use use this to add "login with username or password" option. For example User.findByWhatever(username or email)
would turn into User.find({username: username})
or User.find({email: email})
based on some rules you define.
npm install mongoose-find-by-whatever
Use like any other mongoose plugin and pass an array of rules as the 2nd argument. The order of the rules determines their precedence. A rule can be one of the following:
RegExp
to test against valueFunction
that will get passed the value"ObjectId"
will search by _id"*"
will match anythingvar whatevers = [{propertyName: rule}, {propertyName: rule}, ...];
UserSchema.plugin(require('mongoose-find-by-whatever'), [propertyName: rule]);
// Given a User model
var UserSchema = mongoose.Schema({ name: String , email: String });
// define some finder rules
var whatevers = [
{email: /@/} // Regexp
, {_id: 'ObjectId'} // ObjectId
, {secret: function (value) { return value.indexOf('secret') !== -1; }}
, {name:'*'} // Everything
];
UserSchema.plugin(require('mongoose-find-by-whatever'), whatevers);
User = mongoose.model('User', UserSchema);
User.findByWatever('bob@email.com') // Turns into User.find({email: 'bob@email.com'})
User.findByWatever('52aa38f7bcd27e0200000024') // Turns into User.find({_id: '52aa38f7bcd27e0200000024'})
User.findByWatever('bob') // Turns into User.find({name: 'bob'})
FAQs
Build find criteria based on input value.
We found that mongoose-find-by-whatever 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.