Registry / database / mongodb-search-interface

mongodb-search-interface

JSON →
library1.2.5jsnpmunverified

mongodb-search-interface v1.2.5 is a lightweight TypeScript utility that builds MongoDB query objects from structured search parameters, commonly used in GraphQL resolvers or REST APIs. It provides a simple function to transform a filter object into a MongoDB query with support for operators like $text, $regex, and comparison operators. Unlike more manual approaches, it offers a declarative way to construct search queries without raw MongoDB query building, ideal for search endpoints. The package is stable but infrequently updated, last release in 2021. It ships TypeScript definitions.

npm install mongodb-search-interface
INSTALL
IMPORT
SIG · MONGODB-SEARCH-INT
M
mongodb-search-interface
databasejavascriptv1.2.5
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.

searchInterface
import { searchInterface } from 'mongodb-search-interface'
import searchInterface from 'mongodb-search-interface'
searchInterface is a named export, not a default one. TypeScript will error if you try default import.
SearchInterfaceInput
import { SearchInterfaceInput } from 'mongodb-search-interface'
const { SearchInterfaceInput } = require('mongodb-search-interface')
TypeScript type export; can be imported as type. No runtime value, so require() is incorrect.
searchInterface (CommonJS)
const { searchInterface } = require('mongodb-search-interface')
const searchInterface = require('mongodb-search-interface')
CommonJS must destructure since the module exports an object with searchInterface.

Demonstrates searchInterface basic usage: transforming a filter object into a MongoDB query with $regex for text search.

import { searchInterface } from 'mongodb-search-interface'; const filter = { name: { $search: 'john' }, age: { $gte: 18 }, city: 'New York' }; const query = searchInterface(filter); console.log(query); // Example output: { name: { $regex: /john/i }, age: { $gte: 18 }, city: 'New York' }
Debug
Known issues
gotchaThe $search operator in filter input triggers $regex conversion, not MongoDB's $text index. This may cause unexpected behavior if you expect full-text search.
fix
Use { $text: { $search: '...' } } manually if you need MongoDB $text indexes.
affects: >=0.0.0
deprecatedThe package is in maintenance mode with no updates since 2021. Not compatible with future MongoDB driver versions.
fix
Consider building queries manually or use a more active library like 'mongo-query-builder'.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: searchInterface is not a function
Default import instead of named import when using ESM.
fix
import { searchInterface } from 'mongodb-search-interface'
Property 'searchInterface' does not exist on type 'typeof import(...)'
Using default import in TypeScript.
fix
Use named import: import { searchInterface } from 'mongodb-search-interface'
Upgrade
Version history
1.2.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
mongodb-search-interface — npm install mongodb-search-interface · libregistry