Skip to content

gordonBusyman/mongo-to-sql-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 file for details

About

This is simple tool to convert mongo query to SQL

Resources

License

Stars

Watchers

Forks

Packages

No packages published