Registry / database / mongo-to-mysql

mongo-to-mysql

JSON →
library1.2.4jsnpmunverified

Utility to convert simple MongoDB query documents into equivalent MySQL SQL statements. Version 1.2.4 is the latest stable release; development appears stalled (no updates since 2019). Supports insert, update, and select with basic operators ($in, $nin, $eq, $ne, $gte, $gt, $lte, $lt) and update modifiers ($set, $inc). Lacks support for $or, $and, $not, nested documents, arrays, or projection. Outputs raw SQL strings without parameterization, posing SQL injection risk. Only works with CommonJS; no TypeScript typings.

npm install mongo-to-mysql
INSTALL
IMPORT
SIG · MONGO-TO-MYSQL
M
mongo-to-mysql
databasejavascriptv1.2.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const MoMy = require('mongo-to-mysql')
import MoMy from 'mongo-to-mysql'
Package is CJS-only; ESM import will fail at runtime.
insert
const MoMy = require('mongo-to-mysql'); MoMy.insert(doc, table)
const { insert } = require('mongo-to-mysql'); insert(doc, table)
Destructuring works but is less common in docs; ensure MoMy is required as default.
update
const MoMy = require('mongo-to-mysql'); MoMy.update(find, update, table)
import { update } from 'mongo-to-mysql'
Package does not support ES modules; use require.

Installs package, converts a MongoDB insert document into an SQL INSERT and a MongoDB update with $gt into a MySQL UPDATE.

const MoMy = require('mongo-to-mysql'); // Insert example let mongoDoc = {userName: "x", password: "y"}; let tableName = "user"; let insertQuery = MoMy.insert(mongoDoc, tableName); console.log(insertQuery); // Output: "insert into user (userName, password) values (x, y)" // Update example with $inc let find = {hour: {$gt: 9}}; let update = {$inc: {visits: 1}}; let updateQuery = MoMy.update(find, update, tableName); console.log(updateQuery); // Output: "update user set visits = visits + 1 where hour > 9"
Debug
Known issues
gotchaValues are interpolated directly into SQL strings without escaping — SQL injection risk when using user input.
fix
Sanitize inputs manually or use parameterized queries; avoid passing untrusted data.
affects: >=1.0.0
gotchaNo support for nested objects or arrays; passing {nested: {key: 1}} will produce incorrect SQL.
fix
Flatten documents before conversion or choose a more advanced library.
affects: >=1.0.0
gotchaOnly supports basic operators: $in, $nin, $eq, $ne, $gte, $gt, $lte, $lt. Operators like $or, $and, $not, $regex are not implemented.
fix
Do not rely on complex query logic; handle compound conditions manually.
affects: >=1.0.0
gotchaPackage is not maintained; last update in 2019. May not work with newer Node.js versions or MySQL changes.
fix
Consider using a more actively maintained library or writing queries directly.
affects: >=1.0.0
deprecatedCJS-only; no ESM or TypeScript support.
fix
Use dynamic import() if needed in ESM projects, but prefer a modern alternative.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: MoMy.insert is not a function
Attempted to import using ES module syntax (import) which returns undefined.
fix
Use const MoMy = require('mongo-to-mysql').
Error: $or operator not supported
Query contains $or which is not implemented.
fix
Rewrite query using supported operators or handle logic manually.
insert into user (userName, password) values ([object Object], undefined)
Passed a nested object or array as a field value.
fix
Ensure all values are primitives (strings, numbers, booleans).
Upgrade
Version history
1.2.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
mongo-to-mysql — npm install mongo-to-mysql · libregistry