PHPackages                             nddcoder/sql-to-mongodb-query - 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. [Database &amp; ORM](/categories/database)
4. /
5. nddcoder/sql-to-mongodb-query

ActiveLibrary[Database &amp; ORM](/categories/database)

nddcoder/sql-to-mongodb-query
=============================

1.3.0(2y ago)2167MITPHPPHP ^8.0

Since Jan 7Pushed 2y ago2 watchersCompare

[ Source](https://github.com/dangdungcntt/sql-to-mongodb-query)[ Packagist](https://packagist.org/packages/nddcoder/sql-to-mongodb-query)[ Docs](https://github.com/dangdungcntt/sql-to-mongodb-query)[ RSS](/packages/nddcoder-sql-to-mongodb-query/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (5)Versions (15)Used By (0)

sql-to-mongodb-query
====================

[](#sql-to-mongodb-query)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d622e26671b22d0732bbb43bf4f7afc9578cac442b24b70c1a89b15266f3be7b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6464636f6465722f73716c2d746f2d6d6f6e676f64622d71756572792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nddcoder/sql-to-mongodb-query)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9c04f29e9d672366e028065cdc11f6a1ad3fc1bbe4905c535089198ccd62409e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64616e6764756e67636e74742f73716c2d746f2d6d6f6e676f64622d71756572792f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572)](https://github.com/dangdungcntt/sql-to-mongodb-query/actions?query=workflow%3Atests+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/b106d6e7a022b0e8e07b421fee03ed0543784bcb136a646dd170c150eaf7f8b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6464636f6465722f73716c2d746f2d6d6f6e676f64622d71756572792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nddcoder/sql-to-mongodb-query)

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

[](#installation)

You can install the package via composer:

```
composer require nddcoder/sql-to-mongodb-query
```

Online Demo
-----------

[](#online-demo)

[SQL To MongoDB Query](https://nddapp.com/sql-to-mongodb-query-converter.html)

GUI phpMongoAdmin
-----------------

[](#gui-phpmongoadmin)

[phpMongoAdmin](https://github.com/dangdungcntt/phpmongoadmin)

Usage
-----

[](#usage)

Parse Find query

```
$parser = new Nddcoder\SqlToMongodbQuery\SqlToMongodbQuery();
$query = $parser->parse("
    SELECT id, username, email, created_at
    FROM users
    USE INDEX active_1_created_at_1
    WHERE active = true and created_at >= date('2021-01-01')
    ORDER BY created_at desc
    LIMIT 10, 20
");

/*
Nddcoder\SqlToMongodbQuery\Model\FindQuery {#473
  +filter: array:2 [
    "active" => true
    "created_at" => array:1 [
      "$gte" => MongoDB\BSON\UTCDateTime {#926
        +"milliseconds": "1609459200000"
      }
    ]
  ]
  +projection: array:4 [
    "id" => 1
    "username" => 1
    "email" => 1
    "created_at" => 1
  ]
  +sort: array:1 [
    "created_at" => -1
  ]
  +limit: 20
  +skip: 10
  +collection: "users"
  +hint: "active_1_created_at_1"
}

*/
```

Parse Aggregate query

```
$parser = new Nddcoder\SqlToMongodbQuery\SqlToMongodbQuery();
$query = $parser->parse("
    SELECT date, count(*)
    FROM clicks
    USE INDEX status_1_created_at_1
    WHERE status = 1 and created_at >= date('2021-07-01')
    GROUP BY date
    HAVING count(*) > 100
");

/*
Nddcoder\SqlToMongodbQuery\Model\Aggregate {#493
  +pipelines: array:4 [
    0 => array:1 [
      "$match" => array:2 [
        "status" => 1
        "created_at" => array:1 [
          "$gte" => MongoDB\BSON\UTCDateTime {#926
            +"milliseconds": "1625097600000"
          }
        ]
      ]
    ]
    1 => array:1 [
      "$group" => array:2 [
        "_id" => array:1 [
          "date" => "$date"
        ]
        "count(*)" => array:1 [
          "$sum" => 1
        ]
      ]
    ]
    2 => array:1 [
      "$project" => array:3 [
        "date" => "$_id.date"
        "count(*)" => "$count(*)"
        "_id" => 0
      ]
    ]
    3 => array:1 [
      "$match" => array:1 [
        "count(*)" => array:1 [
          "$gt" => 100
        ]
      ]
    ]
  ]
  +collection: "clicks"
  +hint: "status_1_created_at_1"
}
*/
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Dung Nguyen Dang](https://github.com/dangdungcntt)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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 ~94 days

Recently: every ~175 days

Total

14

Last Release

777d ago

Major Versions

0.0.7 → 1.0.02021-10-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/108944439?v=4)[nddzee](/maintainers/nddcoder)[@nddcoder](https://github.com/nddcoder)

---

Top Contributors

[![dangdungcntt](https://avatars.githubusercontent.com/u/22521948?v=4)](https://github.com/dangdungcntt "dangdungcntt (68 commits)")

---

Tags

nddcodersql-to-mongodb-query

###  Code Quality

TestsPest

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nddcoder-sql-to-mongodb-query/health.svg)

```
[![Health](https://phpackages.com/badges/nddcoder-sql-to-mongodb-query/health.svg)](https://phpackages.com/packages/nddcoder-sql-to-mongodb-query)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[doctrine/mongodb-odm

PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to MongoDB.

1.1k24.5M358](/packages/doctrine-mongodb-odm)[alcaeus/mongo-php-adapter

Adapter to provide ext-mongo interface on top of mongo-php-library

47012.6M75](/packages/alcaeus-mongo-php-adapter)[ahmed-bhs/doctrine-doctor

Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.

9410.8k](/packages/ahmed-bhs-doctrine-doctor)[leroy-merlin-br/mongolid

Easy, powerful and ultrafast ODM for PHP and MongoDB.

11335.7k9](/packages/leroy-merlin-br-mongolid)

PHPackages © 2026

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