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.
{ 'address.city': 'provo',
name: 'Thomas',
age: { '$gte': '30' } }
becomes
(data->'address'->>'city'='provo') and (data->>'name'='Thomas') and (data->>'age'>='30')
{
$or: [ { qty: { $gt: 100 } }, { price: { $lt: 9.95 } } ]
}
becomes
((data->'qty'>'100'::jsonb) OR (data->'price'<'9.95'::jsonb))
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.