Registry / database / mysql-mongo

mysql-mongo

JSON →
library1.0.0-alpha14jsnpmunverified

A library that lets you query MySQL databases using a MongoDB-like syntax in Node.js. Version 1.0.0-alpha14. Supports ESM and TypeScript with built-in type definitions. Key features include chaining methods like .where(), .field(), .limit(), .skip(), .get(), and MongoDB-style operators (eq, or, regex, like) that compile to SQL. Includes JSON field support with automatic parsing and tinyint-to-boolean conversion. Actively maintained with alpha stability.

npm install mysql-mongo
INSTALL
IMPORT
SIG · MYSQL-MONGO
M
mysql-mongo
databasejavascriptv1.0.0-alpha14
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.

database
import { database } from 'mysql-mongo'
import database from 'mysql-mongo'
database is a named export, not a default export.
defineConfig
import { defineConfig } from 'mysql-mongo'
const defineConfig = require('mysql-mongo').defineConfig
ESM-only library; CommonJS require not supported.
Collection
import type { Collection } from 'mysql-mongo'
import { Collection } from 'mysql-mongo'
Collection is a type, use 'import type' for proper TypeScript tree-shaking.

Shows how to set up a database connection, define a collection, query with MongoDB-like syntax, and close the pool.

import { database, defineConfig } from 'mysql-mongo'; const db = database( defineConfig({ connConfig: { user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: 'test', }, type: 'pool', jsonParse: true, tinyIntToBool: true, }) ); async function run() { const result = await db .collection('users') .where({ name: 'Alice' }) .field({ name: true, age: true }) .limit(1) .get(); console.log(result); await db.close(); } run().catch(console.error);
Debug
Known issues
gotchaThe library is in alpha stage (v1.0.0-alpha14); API may break in future releases.
fix
Pin to specific version and handle updates carefully.
affects: >=1.0.0-alpha
gotchaThe library uses MySQL connection pooling by default; forgetting to call db.close() can lead to connection leaks.
fix
Always call await db.close() after completing queries, especially in short-lived scripts.
affects: >=1.0.0-alpha
gotchajsonParse option automatically converts JSON columns to JavaScript objects; if you store complex JSON, ensure your data is valid JSON to avoid errors.
fix
Verify that JSON columns contain valid JSON strings; handle parsing errors explicitly.
affects: >=1.0.0-alpha
deprecatedThe library currently has no deprecated APIs, but as an alpha, expect breaking changes without deprecation notices.
fix
Monitor the GitHub repository for updates and read changelogs before upgrading.
affects: >=1.0.0-alpha
Errors
Common errors & fixes
Error: Cannot find module 'mysql-mongo'
Package not installed or not in node_modules.
fix
Run 'npm install mysql-mongo' or 'yarn add mysql-mongo'.
TypeError: db.collection is not a function
database() not called correctly; db is likely a config object instead of a database instance.
fix
Ensure you call database(defineConfig(...)) and assign the result to db.
Error: ER_PARSE_ERROR: You have an error in your SQL syntax
Invalid query syntax generated by the library, possibly due to unsupported operations or misused operators.
fix
Double-check your query structure; refer to the documentation for supported operators and methods.
Upgrade
Version history
1.0.0-alpha14latest on npm
Audit
Dependencies
@types/mysqloptionalProvides TypeScript types for the mysql dependency used internally.
Agent activity
5 hits · last 30 days
node
4
Resources
mysql-mongo — npm install mysql-mongo · libregistry