PHPackages                             maurice2k/querycheck - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. maurice2k/querycheck

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

maurice2k/querycheck
====================

Evaluate logical JSON queries (MongoDB style)

1.5.0(5mo ago)150MITPHPPHP ^8.3

Since Oct 30Pushed 5mo agoCompare

[ Source](https://github.com/maurice2k/querycheck-php)[ Packagist](https://packagist.org/packages/maurice2k/querycheck)[ RSS](/packages/maurice2k-querycheck/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

QueryCheck for PHP
==================

[](#querycheck-for-php)

*QueryCheck* is a logical JSON query evaluator which uses the [MongoDB query style](https://docs.mongodb.com/manual/tutorial/query-documents/).

This is a PHP 8.3+ port of the original [JavaScript/Node.js querycheck package](https://github.com/maurice2k/querycheck).

Supported Operators
-------------------

[](#supported-operators)

### Comparison Operators

[](#comparison-operators)

- [$eq](https://docs.mongodb.com/manual/reference/operator/query/eq/) - Matches values that are equal to a specified value
- [$ne](https://docs.mongodb.com/manual/reference/operator/query/ne/) - Matches values that are not equal to a specified value
- [$gt](https://docs.mongodb.com/manual/reference/operator/query/gt/) - Matches values that are greater than a specified value
- [$gte](https://docs.mongodb.com/manual/reference/operator/query/gte/) - Matches values that are greater than or equal to a specified value
- [$lt](https://docs.mongodb.com/manual/reference/operator/query/lt/) - Matches values that are less than a specified value
- [$lte](https://docs.mongodb.com/manual/reference/operator/query/lte/) - Matches values that are less than or equal to a specified value
- [$in](https://docs.mongodb.com/manual/reference/operator/query/in/) - Matches any of the values specified in an array
- [$regex](https://docs.mongodb.com/manual/reference/operator/query/regex/) - Matches values using regular expression pattern matching

### Logical Operators

[](#logical-operators)

- [$and](https://docs.mongodb.com/manual/reference/operator/query/and/) - Joins query clauses with a logical AND
- [$or](https://docs.mongodb.com/manual/reference/operator/query/or/) - Joins query clauses with a logical OR
- [$not](https://docs.mongodb.com/manual/reference/operator/query/not/) - Inverts the effect of a query expression

### Aggregation Expressions (`$expr`)

[](#aggregation-expressions-expr)

- [$expr](https://www.mongodb.com/docs/manual/reference/operator/query/expr/) - Allows aggregation expressions within query predicates

The following operators can be used within `$expr`:

**Arithmetic Operators:**

- [$add](https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/) - Adds numbers together
- [$subtract](https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/) - Subtracts two numbers
- [$multiply](https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/) - Multiplies numbers together
- [$divide](https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/) - Divides two numbers
- [$mod](https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/) - Returns the modulo of two numbers

**Query Operators** (for aggregation context):

- [$eq](https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/) - Returns true if values are equal
- [$ne](https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/) - Returns true if values are not equal
- [$gt](https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/) - Returns true if first value is greater than second
- [$gte](https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/) - Returns true if first value is greater than or equal to second
- [$lt](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/) - Returns true if first value is less than second
- [$lte](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/) - Returns true if first value is less than or equal to second

**Logical Operators:**

- [$not](https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/) - Returns the boolean opposite of an expression
- [$in](https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/) - Returns true if a value is in an array

**Array Operators:**

- [$size](https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/) - Returns the number of elements in an array

**String Operators:**

- [$toLower](https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/) - Converts a string to lowercase
- [$toUpper](https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/) - Converts a string to uppercase
- [$concat](https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/) - Concatenates strings
- [$substr](https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/) - Returns a substring (codepoint-based)
- [$substrBytes](https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/) - Returns a substring (byte-based)
- [$strLenBytes](https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/) - Returns the byte length of a string
- [$strLenCP](https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/) - Returns the codepoint length of a string
- [$trim](https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/) - Removes whitespace or characters from both ends
- [$ltrim](https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/) - Removes whitespace or characters from the start
- [$rtrim](https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/) - Removes whitespace or characters from the end

**Conditional Operators:**

- [$cond](https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/) - Conditional expression with if/then/else branches

**Field References:**Field references within `$expr` use MongoDB syntax with `$` prefix (e.g., `$fieldName`, `$customer.address.city`).

Installation
------------

[](#installation)

Install with Composer:

```
composer require maurice2k/querycheck
```

Simple Example
--------------

[](#simple-example)

```
