Welcome to the new MongoDB Feedback Portal!
{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.
We’ve upgraded our feedback system to better capture, track, and act on your feedback. Here’s what you need to know:
Summary
Developers using the MongoDB Node.js driver (and libraries like Mongoose) rely heavily on aggregation pipelines but currently lack strong TypeScript integration and type inference when constructing complex stages. The aggregate() method does not infer types from the model’s schema, resulting in weak IntelliSense, limited compile-time validation, and loss of type safety across aggregation stages.
Problem
Even in large codebases with consistent model definitions, TypeScript users receive little feedback or autocomplete support when building pipelines. The IDE only reports syntax-level errors (e.g., missing braces), offering no type validation or schema-aware suggestions for stages such as $match, $lookup, $group, $project, $out, or $merge. This makes working with aggregations feel disconnected from the TypeScript ecosystem and pushes some teams toward SQL-based solutions where static typing and IDE integration are more mature.
Proposal
Introduce enhanced TypeScript support for collection.aggregate() and model-based aggregations by:
Inferring the input document type from the model’s generic type parameter.
Propagating inferred output types across each stage in the pipeline to detect incompatible transformations.
Providing IntelliSense and autocompletion for valid aggregation operators and stage fields.
Allowing developers to opt out by explicitly passing any or overriding inference with a generic parameter (aggregate<any>([])).
Considerations
Schema drift across services (e.g., non-TypeScript writers) may reduce inference accuracy, but inference should be best-effort and overridable.
$out and $merge targets cannot be fully typechecked pre-write, but partial validation could still improve confidence.
Some collections will remain intentionally untyped, and inference should gracefully degrade in those cases.
Value
This feature would significantly improve developer experience for TypeScript users by bringing MongoDB aggregation pipelines closer to first-class, type-safe citizens. It would strengthen IDE feedback loops, reduce runtime errors, and make MongoDB a more appealing choice for teams committed to strict typing and robust developer tooling.
This would be similar to https://jira.mongodb.org/browse/NODE-5703