Registry / database / mquery

mquery

JSON →
library6.0.0jsnpmunverified

mquery is a fluent MongoDB query builder for Node.js, version 6.0.0. It provides a chainable API for constructing and executing MongoDB queries, supporting features like geospatial queries, validation, and custom base queries. It is designed to work with the official MongoDB driver and Mongoose. Compared to raw driver usage, mquery offers a more expressive and easier-to-use interface. Release cadence is irregular; the latest version requires Node >=20.19.0.

npm install mquery
INSTALL
IMPORT
SIG · MQUERY
M
mquery
databasejavascriptv6.0.0
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.

mquery
import mquery from 'mquery'
const mquery = require('mquery')
mquery provides a default export. Since v6, it is ESM-only, so require() will not work.
mquery.Collection
import mquery from 'mquery'; const { Collection } = mquery
Collection type is accessed as a property of the default export.
Query
import type { Query } from 'mquery'
import { Query } from 'mquery'
Query is a type; use import type for TypeScript.

Connects to MongoDB, constructs a query for documents with type 'fruit', sorts by name ascending, limits to 10, and executes.

import { MongoClient } from 'mongodb'; import mquery from 'mquery'; const uri = process.env.MONGODB_URI ?? 'mongodb://localhost:27017'; const client = new MongoClient(uri); await client.connect(); const collection = client.db('test').collection('docs'); const docs = await mquery(collection) .find({ type: 'fruit' }) .sort({ name: 1 }) .limit(10) .exec(); console.log(docs); await client.close();
Debug
Known issues
breakingDropped support for Node.js versions below 20.19.0 in v6.
fix
Upgrade Node.js to >=20.19.0 or use mquery v5.x.
affects: >=6.0.0
breakingConverted to pure ESM; CommonJS require() no longer works.
fix
Use import syntax or migrate to CommonJS via dynamic import() if necessary.
affects: >=6.0.0
deprecatedThe `stream()` method is deprecated in favor of cursor streams.
fix
Use `.cursor().stream()` instead.
affects: >=5.0.0
gotchaWhen using `mquery` with Mongoose, you must pass the underlying MongoDB collection, not a Mongoose model.
fix
Use `Model.collection` to get the driver collection.
affects: *
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only module.
fix
Change to import statement: `import mquery from 'mquery';`
TypeError: mquery is not a function
Incorrect import of default export as a named export.
fix
Use `import mquery from 'mquery';` instead of `import { mquery } from 'mquery';`
Query is not a constructor
Using the Query type as a value.
fix
Use the default export `mquery` to create queries, not the Query type.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
debugoptionalDebug logging support for queries.
Agent activity
2 hits · last 30 days
node
2
Resources
packagemquery
mquery — npm install mquery · libregistry