Mongoose plugin that transforms REST query parameters into efficient MongoDB aggregation pipelines. v1.4.2, actively maintained. Automatically generates queries from req.query objects based on schema definitions, supports pagination, text search, autocomplete/regex search, and field protection. Ships TypeScript types. Uses aggregation pipeline for all queries, not Mongoose find(). Requires Mongoose ^8 and Typesense ^3.0.6 as peer dependencies. Differentiator: schema-aware query generation with built-in auto-pagination (will default to true in next major).
npm install mongoose-smart-queryNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Set up a Mongoose model with the smart-query plugin and perform a basic query from a request query object.
Set autoPaginate: false explicitly if you want to keep current behavior, or prepare to handle paginated objects in responses.
If you need Mongoose document methods, use Model.find() directly instead of smartQuery.
Create a text index on fields used in fieldsForDefaultQuery and consider using $text search instead.
Declare your model type as Model<IYourInterface> & SmartQueryStatics.
Use Mongoose schema-level select: false for sensitive fields as an additional layer.
Ensure you add the plugin before calling mongoose.model() and extend your model type with SmartQueryStatics.
Run npm install mongoose-smart-query and ensure peer dependencies mongoose and typesense are installed.
Add fieldsForDefaultQuery to plugin options: { fieldsForDefaultQuery: 'field1 field2' }Import SmartQueryOptions and cast: ...smartQuery(req.query, { autoPaginate: true } as SmartQueryOptions)