You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

mongo-query-parse-filter

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-query-parse-filter

Lightweight package that allows you to easily convert complex, human-readable query filters into MongoDB-compatible query syntax, supporting logical operations like `AND`, `OR`, `NOT`, `IN`, `NIN` and various comparison operators

1.0.5
latest
Source
npm
Version published
Weekly downloads
13
116.67%
Maintainers
0
Weekly downloads
 
Created
Source

Mongo Query Parse Filter

Lightweight package that allows you to easily convert complex, human-readable query filters into MongoDB-compatible query syntax, supporting logical operations like AND, OR, NOT, IN, NIN and various comparison operators

Table of Contents

  • Installation
  • Usage
  • Example

Installation

To install the package, use npm:

npm i mongo-query-parse-filter

Usage

const { MongoQuery } = require('mongo-query-parse-filter');

const mongoQuery = new MongoQuery();

const query = mongoQuery.buildQuery('(email eq "jhon@example.com")')

console.log(query)

Result
{
    "email": { "$eq": "jhon@example.com" }
}

Example

eq,neq,gt,gte,lt,lte,regex: (email regex "(?i)@example.com$")
{
    "email": { "$regex": "(?i)@example.com$" }
}
OR/AND: (email eq "jhon@example.com") or (username eq "alice")
{
    "$or": [
        {
            "email": { "$eq": "jhon@example.com" }
        },
        {
            "username": { "$eq": "alice" }
        }
    ]
}
NOT: (not ((department eq "Marketing") or (department eq "Sales")))

to find all employees who are not either in the Marketing or Sales departments

{
    "$not": {
        "$or": [
            {
                "department": { "$eq": "Marketing" }
            },
            {
                "department": { "$eq": "Sales" }
            }
        ]
    }
}
IN/NIN: (email in "'alice@example.com','jhon@example.com'")
{
    "email": { "$in": [ "alice@example.com", "jhon@example.com"] }
}

Keywords

JIRA Query Language

FAQs

Package last updated on 14 Dec 2024

Did you know?

Socket

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.

Install

Related posts