
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
mongoose-dynamic-querybuilder
Advanced tools
This is Mongoose/Mongo QueryBuilder npm package that can fetch datas dynamically
A utility library for building dynamic queries with Mongoose, featuring enhanced capabilities such as dynamic searching, exclusion of fields, and additional filtering.
Install using npm:
npm i mongoose-dynamic-querybuilder
Or using Yarn:
yarn add mongoose-dynamic-querybuilder
Here's how you can use the QueryBuilder
with a Mongoose model:
import QueryBuilder from "mongoose-dynamic-querybuilder";
// Initialize QueryBuilder with a Mongoose query and request query parameters
const getAllBooks = async (req: any) => {
const booksQuery = new QueryBuilder(Book.find({}), req.query)
await booksQuery
.filter()
.extraFilter({ isDeleted: { $ne: true } })
.search(['name.en', 'name.hi', 'name.local'])
.sort()
.paginate()
.fields()
.exclude('soldCount')
.applyExclusions()
const [books, totalBooks, filters] = await Promise.all([
booksQuery.modelQuery
.populate('categories', 'name name_en name_hi image description')
.populate('publisher', 'name profileImage')
.populate('author', 'name profileImage'),
booksQuery.countTotal(),
booksQuery.getFiltersList(
['categories', 'author', 'publisher', 'language'],
{
categories: Category,
author: User,
publisher: User,
language: null, // if string field make it null
}
),
])
filters.price = booksQuery.getFilters().price
}
new QueryBuilder(query, queryParams)
query
: A Mongoose query instance.queryParams
: An object containing query parameters..filter()
: Apply filters based on queryParams
for fields not directly involved in searching or sorting..search(fields)
: Perform a dynamic search on specified fields..sort()
: Apply sorting based on queryParams
..paginate()
: Paginate the results according to queryParams
..fields()
: Select which fields to return in the query results..exclude(fields)
: Specify fields to exclude from the results..applyExclusions()
: Apply exclusions set by .exclude()
..extraFilter(...filters)
: Apply additional custom filters..modelQuery
: Get the final Mongoose query object..countTotal()
: Count the total number of documents considering all applied filters, without pagination..getFiltersList(fields, models)
: Retrieve distinct values for specified fields and additional related model information if provided..getFilters()
: Get the accumulated filters for the query.Here are a few example API calls:
Search by Term:
GET http://localhost:5000/api/v1/users?searchTerm=nahid
Pagination:
GET http://localhost:5000/api/v1/users?page=1&limit=10
Select Specific Fields:
GET http://localhost:5000/api/v1/users?fields=password,email
Sort in Descending Order:
GET http://localhost:5000/api/v1/users?sort=-username
.extraFilter()
method.FAQs
This is Mongoose/Mongo QueryBuilder npm package that can fetch datas dynamically
The npm package mongoose-dynamic-querybuilder receives a total of 13 weekly downloads. As such, mongoose-dynamic-querybuilder popularity was classified as not popular.
We found that mongoose-dynamic-querybuilder 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.