Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@celleb/mongoorrhea
Advanced tools
Restful query builder for mongodb with mongoose using your url query
npm i @celleb/auto-query
import { Schema } from 'mongoose';
const userSchema = new Schema({
name: String,
surname: String,
likes: [String],
car: [
{
model: String,
year: Number,
},
],
activities: [
{
name: String,
},
],
});
The dictionary is used to transform the api fields to the database fields. If the fields are the same then you can exclude it from the dictionary. The dictionary is POJO with string for both keys and values.
For example {apiField: 'databaseField' }
// shallow/flat dictionary/map
const dictionary = {
firstName: 'name',
lastName: 'surname',
'vehicle.model': 'car.model',
'vehicle.year': 'car.year',
};
The AutoQuery
takes a model and a dictionary.
import { AutoQuery } from '@celleb/auto-query';
import mongoose from 'mongoose';
const User = mongoose.model('User', userSchema);
const qb = new AutoQuery(User, dictionary);
Call the query builder's .build
method with the request query.
The build method returns a Mongoose
query and you can chain other methods before calling .exec()
.
async function routHandler(req: Request, res: Response) {
return res.json(await qb.build(req.query).exec());
}
The following are fields support on the query
interface QueryParams = {
match?: Record<string, string|number|Array<string|number>>;
sort?: string;
skip?: number;
limit?: number;
select?: string[];
}
For example: url?match[firstName]=Jonas&sort=firstName&skip=0&limit=10&select=firstName&select=lastName
.
You decide how you encode and decode your url query but the decoded query must match the Query Parameter Interface above.
Allows you to query the database using specific fields and operators.
Symbol | Description | Usage |
---|---|---|
= | Equal to or [in]. Do not add an additional equal sign | url?match[firstName]=Jonas or with array url?match[firstName]=Jonas,Jon ' |
! | Not equal to to or not in [nin]. | url?match[firstName]=!Jonas or with array url?match[likes]=Football,!Tennis ' |
>: | Greater than or equal | url?match[vehicle.year]=>:2017 |
> | Greater than | url?match[vehicle.year]=>2017 |
<: | Less than or equal | url?match[vehicle.year]=<:2017 |
< | Less than or equal | url?match[vehicle.year]=<2017 |
More operations will be added in the future
Specifies the field and the order by which to sort the results.
Use sort?=-fieldName
for descending order and sort=fieldName
for ascending order.
Specifies the number of records to skip in the database.
For example skip=10
skips the first 10 records.
Limits the number of matching records returned.
Example limit=10
returns the first 10 results.
FAQs
Restful query builder for mongodb with mongoose
We found that @celleb/mongoorrhea 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.