Skip to content

Converts MongoDB queries to postgresql queries for jsonb fields.

License

Notifications You must be signed in to change notification settings

MrFlox/mongo-query-to-postgres-jsonb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongo-Postgres Query Converter

MongoDB query documents are useful, but only work with Mongo. This converts a Mongo query to a PostgreSQL WHERE clause on data stored in a json/jsonb field.

Example 1

{ 'address.city': 'provo',
  name: 'Thomas',
  age: { '$gte': '30' } }

becomes

(data->'address'->>'city'='provo') and (data->>'name'='Thomas') and (data->>'age'>='30')

Example 2

{
     $or: [ { qty: { $gt: 100 } }, { price: { $lt: 9.95 } } ]
}

becomes

((data->'qty'>'100'::jsonb) OR (data->'price'<'9.95'::jsonb))

Getting Started

npm install mongo-query-to-postgres-jsonb
var mongoToPostgres = require('mongo-query-to-postgres-jsonb');
mongoToPostgres('data', query)

The first parameter is the name of your jsonb column in your postgres table. The second parameter is the Mongo style query.

Supported Features

  • $eq, $gt, $gte, $lt, $lte, $ne
  • $or, $not
  • $in, $nin
  • $elemMatch
  • $regex

Todo

Can't support

See also

About

Converts MongoDB queries to postgresql queries for jsonb fields.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.6%
  • Dockerfile 1.5%
  • Shell 0.9%