Registry / database / mongodb-query-operators

mongodb-query-operators

JSON →
library1.0.0jsnpmunverified

A utility package providing a structured set of constants and helpers for MongoDB query operators. Version 1.0.0 (stable, no active updates). It includes all standard MongoDB query operators ($lt, $gt, $in, $regex, etc.) and supports both ESM and CommonJS. No dependencies. Unlike manual strings, it reduces typos and improves autocomplete. Released as a single static object, not a constructor.

npm install mongodb-query-operators
INSTALL
IMPORT
SIG · MONGODB-QUERY-OPER
M
mongodb-query-operators
databasejavascriptv1.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.

QueryOperators
import { QueryOperators } from 'mongodb-query-operators'
const QueryOperators = require('mongodb-query-operators').default
Named export only, not default. CommonJS requires destructuring.
default import
import { QueryOperators } from 'mongodb-query-operators'
import QueryOperators from 'mongodb-query-operators'
No default export; only named export exists.
require
const { QueryOperators } = require('mongodb-query-operators')
const QueryOperators = require('mongodb-query-operators')
Direct require yields an object with a 'default' key; use destructuring.

Creates a MongoDB query object using operator constants from the package.

import { QueryOperators } from 'mongodb-query-operators'; // Build a simple query using operators const query = { [QueryOperators.And]: [ { age: { [QueryOperators.GreaterThan]: 18 } }, { status: { [QueryOperators.In]: ['active', 'pending'] } }, { name: { [QueryOperators.Regex]: /^J/i } } ] }; console.log(JSON.stringify(query, null, 2)); // Output: // { // "$and": [ // { "age": { "$gt": 18 } }, // { "status": { "$in": ["active", "pending"] } }, // { "name": { "$regex": /^J/i } } // ] // }
Debug
Known issues
gotchaTextOperators nested object requires accessing via QueryOperators.TextOperators.Search, not as a direct property.
fix
Use QueryOperators.TextOperators.Search instead of QueryOperators['$search'].
affects: >=1.0.0
gotchaThe package does not validate operator combinations; invalid MongoDB queries may be constructed.
fix
Validate queries against the MongoDB documentation or use a schema validator.
affects: >=1.0.0
deprecatedNo known deprecations in v1.0.0, but the package has not been updated since release.
fix
Consider using a more actively maintained alternative like 'mongodb' driver's built-in constants.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading '$lt')
Attempting to access QueryOperators after importing the default instead of named export.
fix
Use import { QueryOperators } from 'mongodb-query-operators' or const { QueryOperators } = require('mongodb-query-operators').
Module not found: Can't resolve 'mongodb-query-operators'
Package not installed or import path misspelled.
fix
Run npm install mongodb-query-operators and confirm the import string matches 'mongodb-query-operators'.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
mongodboptionalOptional: only needed if used with the MongoDB driver directly
Agent activity
4 hits · last 30 days
node
4
Resources
mongodb-query-operators — npm install mongodb-query-operators · libregistry