All Projects → orgoldfus → sql2mongo

orgoldfus / sql2mongo

Licence: MIT license
Use SQL to query MongoDB

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sql2mongo

Mevn Stack
A Quickstart for building an Express API with a VueJS Admin Portal
Stars: ✭ 178 (+1171.43%)
Mutual labels:  mongo
MongoDB-University
Repo for All MongoDB University Courses
Stars: ✭ 102 (+628.57%)
Mutual labels:  mongo
polymorphia
A very fast POJO codec for MongoDB (used in conjunction with the Mongo Java Driver) that handles generic types as well as polymorphic class hierarchies
Stars: ✭ 21 (+50%)
Mutual labels:  mongo
Chartbrew
Open-source web platform for creating charts out of different data sources (databases and APIs) 📈📊
Stars: ✭ 199 (+1321.43%)
Mutual labels:  mongo
Odmantic
Async ODM (Object Document Mapper) for MongoDB based on python type hints
Stars: ✭ 240 (+1614.29%)
Mutual labels:  mongo
BroadcastBot
A simple Telegram bot that can broadcast messages and media to the bot subscribers. with mongo DB support
Stars: ✭ 73 (+421.43%)
Mutual labels:  mongo
Bigdata docker
Big Data Ecosystem Docker
Stars: ✭ 161 (+1050%)
Mutual labels:  mongo
flatbson
Recursively flatten a Go struct using its BSON tags
Stars: ✭ 54 (+285.71%)
Mutual labels:  mongo
docker-mongo
MongoDB Docker image embedding RocksDB storage engine
Stars: ✭ 32 (+128.57%)
Mutual labels:  mongo
gitbot
The most popular Discord dev toolkit with 400k+ users 🚀✨
Stars: ✭ 59 (+321.43%)
Mutual labels:  mongo
Mern Passport
A boilerplate example of using passport.js for authenticating a MERN application
Stars: ✭ 214 (+1428.57%)
Mutual labels:  mongo
Php Mongo
MongoDB ODM. Part of @PHPMongoKit
Stars: ✭ 228 (+1528.57%)
Mutual labels:  mongo
weightless-orm
🛸 A lightweight database mapping library
Stars: ✭ 24 (+71.43%)
Mutual labels:  mongo
Aspnetcore.identity.mongo
This is a MongoDB provider for the ASP.NET Core 2 Identity framework
Stars: ✭ 179 (+1178.57%)
Mutual labels:  mongo
mongo-rust-driver
Mongo Rust driver built on top of the Mongo C driver
Stars: ✭ 89 (+535.71%)
Mutual labels:  mongo
Mongo Cluster Docker
Docker compose config for mongodb cluster
Stars: ✭ 165 (+1078.57%)
Mutual labels:  mongo
nestjs-api-mongoose
Collection example apps with NestJS and Typeorm, Sequelize, Mongodb, PostgreSQL, MySQL, GraphQL, Mercurius, etc. for the NestJS community 😻
Stars: ✭ 153 (+992.86%)
Mutual labels:  mongo
pymongo inmemory
A mongo mocking library with an ephemeral MongoDB running in memory.
Stars: ✭ 25 (+78.57%)
Mutual labels:  mongo
SonataDoctrineMongoDBAdminBundle
Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
Stars: ✭ 64 (+357.14%)
Mutual labels:  mongo
ark.db
Small and fast JSON database for Node and browser. 😋
Stars: ✭ 65 (+364.29%)
Mutual labels:  mongo

sql2mongo Build Status npm

Use SQL syntax to query MongoDB

Installation

npm install sql2mongo

Usage

getMongoQuery

Parses an SQL WHERE clause to a mongo query object.

Example:

const { getMongoQuery } = require("sql2mongo");

const mongoQuery = getMongoQuery(`
  show = "Friends" OR
  (city = "New York" AND
  year BETWEEN 2005 AND 2014 AND
  name IN ("Ted", "Marshall", "Barney"))
`)

Result:

{
  $or: [
    { show: "Friends" },
    {
      city: "New York",
      year: { $gt: 2005, $lt: 2014 },
      name: { $in: ["Ted", "Marshall", "Barney"] },
    }
  ]
}

Nested objects

If you need to query a nested object, use the NESTED function inside your query. The NESTED function receives a string with a WHERE clause for the nested object.

Example: If you would like to query the following nested document:

{
  item: 'journal',
  qty: 25,
  size: { h: 14, w: 21, uom: 'cm' },
  status: 'A'
}

You can use the NESTED function like this:

const { getMongoQuery } = require("sql2mongo");

const mongoQuery = getMongoQuery(`
  size = NESTED("h = 14 AND w > 20")
`)

Result:

{
  size: {
    h: 14,
    w: { $gt: 20 }
  }
}

Otherwise, you can use the dot annotation:

const { getMongoQuery } = require("sql2mongo");

const mongoQuery = getMongoQuery(`
  size.h = 14 AND 
  size.w > 20
`)

Result:

{
  "size.h": 14,
  "size.w": { $gt: 20 }
}

TODO

  • Add support for all DML commands (insert, update, etc.)

Build

  • Run npm run build to build the package.

LICENSE

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].