# mongo-to-sql-converter

> MongoDB queries to SQL converter

Latest version **1.1.2** (published 2021-01-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongo-to-sql-converter
pnpm add mongo-to-sql-converter
yarn add mongo-to-sql-converter
bun add mongo-to-sql-converter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2021-01-31 |
| First published | 2019-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 40 |
| Author | Ivan Tarbakou |
| Maintainers | gordonbusyman |
| Keywords | mongodb, sql, translator, parser, query |

## Links

- npm: https://www.npmjs.com/package/mongo-to-sql-converter
- Repository: https://github.com/gordonBusyman/mongo-to-sql-converter
- Homepage: https://github.com/gordonBusyman/mongo-to-sql-converter#readme
- Issues: https://github.com/gordonBusyman/mongo-to-sql-converter/issues
- npm.io page: https://npm.io/package/mongo-to-sql-converter

## Dependencies (2)

- [json5](https://npm.io/package/json5.md) ^2.1.3
- [mongo-parse](https://npm.io/package/mongo-parse.md) ^2.1.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.1.2 (latest) — 2021-01-31
- 1.1.1 — 2019-10-18
- 1.1.0 — 2019-10-08
- 1.0.1 — 2019-10-08
- 1.0.0 — 2019-10-07

## README

# mongo-to-sql-converter
This is simple tool to convert MongoDB query (```find()```) to SQL


The package takes string as input and gives string as output. It supports only _db.find_ method and throws an exception when another method used.

## Getting Started

### Installing

```
npm i mongo-to-sql-converter
```

### Usage


```
var mongoToSqlConverter = require("mongo-to-sql-converter")

const MongoDBQuery = "db.user.find({age: {$gte: 21}, name: 'julio', contribs: { $in: [ 'ALGOL', 'Lisp' ]}},{name: 1, _id: 1});"
const SQLQuery = mongoToSqlConverter.convertToSQL(MongoDBQuery, true)

console.log(SQLQuery)
```

```removeUnderscoreBeforeID``` flag, if ```true``` will convert \_id to id, default ```false``` 

List of supported operators in MongoDB query

* $or
* $and
* $lt
* $lte
* $gt
* $gte
* $ne
* $in



## Running the tests

Run demo with predefined parameters
```
npm run demo
```

Run the test
```
npm run test
``` 

## License

This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/gordonBusyman/mongo-to-sql-converter/blob/master/LICENSE) file for details

---
_Source: https://npm.io/package/mongo-to-sql-converter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
