
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-query-parser
Advanced tools
Convert url query string to MongooseJs friendly query object including advanced filtering, sorting, population, string template, type casting and many more...
Convert url query string to MongooseJs friendly query object including advanced filtering, sorting, population, string template, type casting and many more...
The library is built highly inspired by api-query-params
$in
, $regexp
, …) and features (paging, projection, population, type casting, string templates…)fields
v.s. select
) and optionsimport { MongooseQueryParser } from 'mongoose-query-parser';
const parser = new MongooseQueryParser(options?: ParserOptions)
parser.parse(query: string, predefined: any) : QueryOptions
ParserOptions
: object for advanced options (See below) [optional]query
: query string part of the requested API URL (ie, firstName=John&limit=10
). Works with already parsed object too (ie, {status: 'success'}
) [required]predefined
: object for predefined query context [optional]QueryOptions
: object contains the following properties:
filter
which contains the query criteriapopulate
which contains the query population. Please see Mongoose Populate for more detailsselect
which contains the query projectionsort
, skip
, limit
which contains the cursor modifiers for paging purposeimport { MongooseQueryParser } from 'mongoose-query-parser';
const parser = new MongooseQueryParser();
const predefined = {
vip: { name: { $in: ['Google', 'Microsoft', 'NodeJs'] } }
sentStatus: 'sent'
};
const query = parser.parse('${vip}&status=${sentStatus}×tamp>2017-10-01&author.firstName=/john/i&limit=100&skip=50&sort=-timestamp&select=name&populate=children', predefined);
{
filter: {
{ name: { $in: ['Google', 'Microsoft', 'NodeJs'] } },
status: 'sent',
timestamp: { $gt: Fri Jan 01 2017 01:00:00 GMT+0100 (CET) },
'author.firstName': /john/i
},
sort: { timestamp: -1 },
skip: 50,
limit: 100,
select: { name },
populate: [{ path: 'children'}]
}
MongoDB | URI | Example | Result |
---|---|---|---|
$eq | key=val | type=public | {filter: {type: 'public'}} |
$gt | key>val | count>5 | {filter: {count: {$gt: 5}}} |
$gte | key>=val | rating>=9.5 | {filter: {rating: {$gte: 9.5}}} |
$lt | key<val | createdAt<2016-01-01 | {filter: {createdAt: {$lt: Fri Jan 01 2016 01:00:00 GMT+0100 (CET)}}} |
$lte | key<=val | score<=-5 | {filter: {score: {$lte: -5}}} |
$ne | key!=val | status!=success | {filter: {status: {$ne: 'success'}}} |
$in | key=val1,val2 | country=GB,US | {filter: {country: {$in: ['GB', 'US']}}} |
$nin | key!=val1,val2 | lang!=fr,en | {filter: {lang: {$nin: ['fr', 'en']}}} |
$exists | key | phone | {filter: {phone: {$exists: true}}} |
$exists | !key | !email | {filter: {email: {$exists: false}}} |
$regex | key=/value/<opts> | email=/@gmail\.com$/i | {filter: {email: /@gmail.com$/i}} |
$regex | key!=/value/<opts> | phone!=/^06/ | {filter: {phone: { $not: /^06/}}} |
For more advanced usage ($or
, $type
, $elemMatch
, etc.), pass any MongoDB query filter object as JSON string in the filter
query parameter, ie:
parser.parse('filter={"$or":[{"key1":"value1"},{"key2":"value2"}]}');
// {
// filter: {
// $or: [
// { key1: 'value1' },
// { key2: 'value2' }
// ]
// },
// }
FAQs
Convert url query string to MongooseJs friendly query object including advanced filtering, sorting, population, string template, type casting and many more...
The npm package mongoose-query-parser receives a total of 1,223 weekly downloads. As such, mongoose-query-parser popularity was classified as popular.
We found that mongoose-query-parser 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.