PHPackages                             tico/mongo-sql-where - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tico/mongo-sql-where

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tico/mongo-sql-where
====================

Convert MongoDB-style queries into SQL WHERE clauses in PHP

v1.0.1(10mo ago)017MITPHPPHP &gt;=8.0CI passing

Since Aug 17Pushed 10mo agoCompare

[ Source](https://github.com/uribes78/mongo-sql-where)[ Packagist](https://packagist.org/packages/tico/mongo-sql-where)[ RSS](/packages/tico-mongo-sql-where/feed)WikiDiscussions main Synced today

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

Mongo SQL Where
===============

[](#mongo-sql-where)

Convert MongoDB-style query syntax into SQL WHERE clauses in PHP.

Features
--------

[](#features)

- Supports `$or`, `$and`, `$not`, `$in`, `$nin`, `$gt`, `$lt`, `$gte`, `$lte`, `$ne`, `$regex`
- Column mapping for aliasing logical keys to SQL columns
- No ORM required

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

[](#installation)

```
composer require tico/mongo-sql-where
```

Usage
-----

[](#usage)

```
use Tico\MongoSqlWhere\MongoQueryToSql;

$query = [
    '$or' => [
        ['status' => 'active'],
        ['qty' => ['$lt' => 50]]
    ],
    '$not' => ['category' => ['$in' => ['banned', 'restricted']]]
];

$map = [
    'status' => 'users.status',
    'qty' => 'products.qty',
    'category' => 'products.category'
];

$converter = new MongoQueryToSql($map);
echo $converter->convert($query);
```

Example Output
--------------

[](#example-output)

```
WHERE (users.status = 'active' OR products.qty  ['$regex' => '^test']];
// Converts to: WHERE name REGEXP '^test'

// Case-insensitive regex
$query = [
    'email' => [
        '$regex' => '@example\\.com$',
        '$options' => 'i'  // 'i' for case-insensitive
    ]
];
// Converts to: WHERE LOWER(email) REGEXP LOWER('@example\\.com$')

// In complex queries
$query = [
    'status' => 'active',
    '$or' => [
        ['name' => ['$regex' => '^A']],
        ['email' => ['$regex' => '@example\\.com$', '$options' => 'i']]
    ]
];
$map = [
    'status' => 'users.status',
    'name' => 'users.name',
    'email' => 'users.email'
];

$converter = new MongoQueryToSql($map);
echo $converter->convert($query);
```

Example Output
--------------

[](#example-output-1)

```
WHERE (users.status = 'active' OR users.name REGEXP '^A') AND (LOWER(users.email) REGEXP LOWER('@example\\\.com$'))
```

License
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance54

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

320d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e911cecb28b0f817fb5d2ea9d8b98ab1ce5d31f5b82f48e4582f7dd724dede45?d=identicon)[uribes78](/maintainers/uribes78)

---

Top Contributors

[![uribes78](https://avatars.githubusercontent.com/u/18754899?v=4)](https://github.com/uribes78 "uribes78 (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tico-mongo-sql-where/health.svg)

```
[![Health](https://phpackages.com/badges/tico-mongo-sql-where/health.svg)](https://phpackages.com/packages/tico-mongo-sql-where)
```

###  Alternatives

[maiorano84/shortcodes

Implement Shortcode syntax anywhere

7766.0k5](/packages/maiorano84-shortcodes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
