How to use the mongo-query-to-postgres-jsonb.countUpdateSpecialKeys 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
}
    socket.write(build(reqId, data, data))
    return true
  }
  if (commandName === 'update') {
    const update = doc.updates[0]
    const where = mongoToPostgres('data', update.q, getArrayPaths(rawCollectionName))
    let res
    try {
      const newValue = mongoToPostgres.convertUpdate('data', update.u)
      // TODO (handle multi)
      await createTable(collectionName)
      res = await doQuery(databaseName, `UPDATE ${collectionName} SET data = ${newValue} WHERE ${where}`)
      if (res.rowCount === 0 && update.upsert) {
        const changes = update.u || {}
        if (mongoToPostgres.countUpdateSpecialKeys(changes) === 0) {
          // TODO: expand dot notation
          _.assign(changes, update.q)
        } else {
          changes['$set'] = changes['$set'] || {}
          _.assign(changes['$set'], update.q)
        }
        const newValue = mongoToPostgres.convertUpdate('data', changes, true)
        async function insert() {
          const res = await doQuery(databaseName, `INSERT INTO ${collectionName} VALUES (${newValue})`)
          const data = { n: res.rowCount, nInserted: res.rowCount, updatedExisting: false, ok: 1 }
          socket.write(build(reqId, data, {}))
        }

        await tryOrCreateTable(insert, databaseName, collectionName)
        return true
      } else {

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