How to use the mongo-query-to-postgres-jsonb.convertSort function in mongo-query-to-postgres-jsonb

To help you get started, we’ve selected a few mongo-query-to-postgres-jsonb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thomas4019 / pgmongo / index.js View on Github external
debug('pgmongo:rows')(rows)
    const data = { values: rows, ok: 1 }
    socket.write(build(reqId, data, {}))
    return true
  }
  if (commandName === 'find') {
    const filter = doc.filter
    const where = safeWhereConversion(filter, rawCollectionName)
    let select = mongoToPostgres.convertSelect('data', doc.projection)

    let query = `SELECT ${select} FROM ${collectionName}`
    if (where !== 'TRUE') {
      query += ` WHERE ${where}`
    }
    if (doc.sort) {
      query += ' ORDER BY ' + mongoToPostgres.convertSort('data', doc.sort, doc.collation && doc.collation.numericOrdering)
    }
    if (doc.limit) {
      query += ' LIMIT ' + Math.abs(doc.limit)
    }
    if (doc.skip) {
      if (doc.skip < 0) {
        socket.write(build(reqId, { ok: 0, errmsg: 'negative skip not allowed' }, {}))
        return true
      }
      query += ' OFFSET ' + doc.skip
    }
    let res
    try {
      res = await tryOrCreateTable(async () => await doQuery(databaseName, query), databaseName, collectionName)
    } catch (e) {
      console.error(e)

mongo-query-to-postgres-jsonb

Converts MongoDB queries to postgresql queries for jsonb fields.

MIT
Latest version published 3 months ago

Package Health Score

65 / 100
Full package analysis