Skip to content

MongoDB indexes support#3795

Open
radovanradic wants to merge 35 commits into5.0.xfrom
radovanradic/mongodb-indexes
Open

MongoDB indexes support#3795
radovanradic wants to merge 35 commits into5.0.xfrom
radovanradic/mongodb-indexes

Conversation

@radovanradic
Copy link
Copy Markdown
Contributor

Requested in issue #3794

Copilot AI review requested due to automatic review settings April 2, 2026 12:06
Co-authored-by: Radovan Radic <radicr@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds declaration-based MongoDB index / collection option support in Micronaut Data MongoDB, including startup index creation/reconciliation, validation, and extensive test coverage (plus docs updates) to address issue #3794.

Changes:

  • Introduce MongoDB index/collection annotations (single-field, compound, text, hashed, geo, wildcard, clustered) and related configuration (create-indexes + failure policy).
  • Extend Mongo collection initialization to support reading existing collection/index state, reconciling managed definitions, and creating indexes at startup (sync + reactive).
  • Add user documentation and a large Spock test suite covering index creation and validation scenarios.

Reviewed changes

Copilot reviewed 98 out of 98 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/docs/guide/toc.yml Adds a MongoDB Indexes page to the Mongo mapping docs TOC.
src/main/docs/guide/mongo/mongoMapping/mongoIndexes.adoc New guide page documenting MongoDB index annotations and startup behavior/config.
data-mongodb/src/test/java/io/micronaut/data/document/mongodb/entities/Test.java Updates test entity with a GeoJSON MultiPoint field.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/init/AbstractMongoCollectionsCreatorSpec.groovy Unit tests for resolving index/collection options and command documents.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/wildcard/toplevel/multiple/MongoTopLevelWildcardMultipleDeclarationsIndexCreationSpec.groovy Integration tests for merging/reconciling multiple top-level wildcard declarations.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/wildcard/toplevel/MongoTopLevelWildcardProjectionIndexCreationSpec.groovy Integration test for top-level wildcard index with projection.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/wildcard/toplevel/MongoTopLevelWildcardIndexCreationSpec.groovy Integration test for top-level wildcard index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/wildcard/MongoWildcardIndexCreationSpec.groovy Integration test for field-level wildcard index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/wildcardtoplevelmultiple/MongoTopLevelWildcardMultipleDeclarationsValidationSpec.groovy Validation test allowing multiple top-level wildcard projections.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/wildcardprojection/MongoWildcardProjectionValidationSpec.groovy Validation test rejecting field-level wildcard projection.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/ttlcompound/MongoCompoundIndexTtlValidationSpec.groovy Validation test rejecting TTL on compound index.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/textversionconflict/MongoTextIndexVersionConflictSpec.groovy Validates fail-fast behavior on existing text index version conflicts.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/textversionconflict/MongoReactiveTextIndexVersionConflictSpec.groovy Reactive-driver variant of text index version conflict validation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/text/MongoTextIndexValidationSpec.groovy Validation test for invalid text weight.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/storageengine/MongoStorageEngineValidationSpec.groovy Validation test for invalid storageEngine JSON.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/partialfilter/MongoCompoundIndexPartialFilterValidationSpec.groovy Validation test for sparse + partialFilterExpression incompatibility.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/options/MongoIndexAdvancedOptionsResolutionSpec.groovy Tests runtime resolution/validation of advanced index options.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/invalidpath/MongoCompoundIndexValidationSpec.groovy Validation test for invalid compound index paths.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/indexfailurepolicy/MongoIndexFailurePolicyWarnContinueSpec.groovy Tests WARN_AND_CONTINUE startup behavior on index init failure.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/indexbootstrap/MongoReactiveIndexBootstrapWithoutCollectionsSpec.groovy Reactive variant for index bootstrap when collections already exist.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/indexbootstrap/MongoIndexBootstrapWithoutCollectionsSpec.groovy Verifies index creation when collections exist and create-collections is disabled.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/geotypevalid/MongoGeoTypeValidSpec.groovy Validation test for supported GeoJSON property type.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/geotype/MongoGeoTypeValidationSpec.groovy Validation test for unsupported geospatial property type.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/geosphereversion/MongoGeoSphereVersionValidationSpec.groovy Validation test for invalid sphereVersion usage.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/georules/MongoGeoIndexValidationSpec.groovy Validation test for invalid geo option combinations (2d vs 2dsphere).
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/geocompoundopts2d/MongoCompoundGeo2dOptionsValidationSpec.groovy Validation for compound geo 2d option rules.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/geocompoundopts/MongoCompoundGeoOptionsValidationSpec.groovy Validation for compound geo option rules.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/geocompoundopts/MongoCompoundGeo2dOptionsValidationSpec.groovy Validation for compound geo 2d option rules (alt package).
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/geocompound/MongoCompoundGeoValidationSpec.groovy Validation test for compound geo field direction conflicts.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/geobits/MongoGeoBitsValidationSpec.groovy Validation test for out-of-range 2d bits.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/existingindexname/MongoExistingIndexNameReconciliationSpec.groovy Tests name conflict vs name-less reconciliation with existing indexes.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/existingindexconflict/MongoReactiveExistingIndexConflictSpec.groovy Reactive variant for existing-index option conflicts.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/existingindexconflict/MongoExistingIndexConflictSpec.groovy Tests conflicts with existing indexes (unique/collation/partial filter).
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/existingindexcompatibility/MongoExistingIndexCompatibilitySpec.groovy Tests compatibility when matching indexes already exist.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/existingindexadvancedconflict/MongoReactiveExistingIndexAdvancedConflictSpec.groovy Reactive variant for advanced existing-index conflicts.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/existingindexadvancedconflict/MongoExistingIndexAdvancedConflictSpec.groovy Tests advanced conflict detection (TTL/geo/text/wildcard/storageEngine/etc.).
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/existingclusteredconflict/MongoExistingClusteredCollectionConflictSpec.groovy Tests clustered collection option conflicts.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/existingclusteredcompatibility/MongoExistingClusteredCollectionCompatibilitySpec.groovy Tests clustered collection option compatibility.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/emptyfields/MongoCompoundIndexEmptyFieldsValidationSpec.groovy Validation test for empty compound fields list.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/duplicatefield/MongoCompoundIndexDuplicateFieldValidationSpec.groovy Validation test for duplicate compound field paths.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/collation/MongoCollationValidationSpec.groovy Validation test for invalid collation JSON.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/clusteredunique/MongoClusteredUniqueValidationSpec.groovy Validation test for clustered unique=false.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/clusteredttlvalid/MongoClusteredTtlValidSpec.groovy Validation test for clustered TTL with supported id type.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/validation/clusteredttl/MongoClusteredTtlValidationSpec.groovy Validation test for clustered TTL with unsupported id type.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/ttl/MongoTtlIndexCreationSpec.groovy Integration test for TTL index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/text/MongoTextIndexCreationSpec.groovy Integration test for text index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/text/MongoAggregatedTextIndexCreationSpec.groovy Integration test intended for aggregated text index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/text/embedded/MongoEmbeddedTextIndexCreationSpec.groovy Integration test for text index declared inside embedded type.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/simple/MongoIndexCreationSpec.groovy Integration test for basic single-field index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/simple/embedded/MongoEmbeddedFieldIndexCreationSpec.groovy Integration test for single-field index declared inside embedded type.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/reactive/ttl/MongoReactiveTtlIndexCreationSpec.groovy Reactive-driver variant for TTL index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/reactive/text/MongoReactiveTextIndexCreationSpec.groovy Reactive-driver variant for text index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/reactive/text/MongoReactiveAggregatedTextIndexCreationSpec.groovy Reactive-driver variant for aggregated text index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/reactive/partialfilter/MongoReactivePartialFilterIndexCreationSpec.groovy Reactive-driver variant for partialFilter index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/reactive/MongoReactiveIndexCreationSpec.groovy Reactive-driver variant for basic index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/partialfilter/MongoPartialFilterIndexCreationSpec.groovy Integration test for partialFilterExpression index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/hidden/MongoHiddenIndexCreationSpec.groovy Integration tests for hidden indexes (single + compound).
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/hashed/MongoHashedIndexCreationSpec.groovy Integration test for hashed index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geovalue/polygon/MongoGeoPolygonValueIndexCreationSpec.groovy Integration tests for 2dsphere on Polygon and persistence round-trip.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geovalue/multipolygon/MongoGeoMultiPolygonValueIndexCreationSpec.groovy Integration tests for 2dsphere on MultiPolygon and persistence round-trip.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geovalue/multipoint/MongoGeoMultiPointValueIndexCreationSpec.groovy Integration tests for 2dsphere on MultiPoint and persistence round-trip.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geovalue/multilinestring/MongoGeoMultiLineStringValueIndexCreationSpec.groovy Integration tests for 2dsphere on MultiLineString and persistence round-trip.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geovalue/MongoGeoPointValueIndexCreationSpec.groovy Integration test for 2dsphere on Point.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geovalue/linestring/MongoGeoLineStringValueIndexCreationSpec.groovy Integration tests for 2dsphere on LineString and persistence round-trip.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geovalue/geometrycollection/MongoGeoGeometryCollectionValueIndexCreationSpec.groovy Integration test for 2dsphere on GeometryCollection.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geocompound/options/MongoCompoundGeo2dOptionsIndexCreationSpec.groovy Integration test for compound index with geo 2d options.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geocompound/MongoCompoundGeoIndexCreationSpec.groovy Integration test for compound index with geo field (2dsphere).
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geo2d/options/MongoGeo2dOptionsIndexCreationSpec.groovy Integration test for 2d index with options.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geo2d/MongoGeo2dIndexCreationSpec.groovy Integration tests for 2d index and map-backed persistence.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/geo/MongoGeoIndexCreationSpec.groovy Integration test for 2dsphere index creation (with sphereVersion).
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/compound/MongoCompoundIndexCreationSpec.groovy Integration test for compound index creation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/compound/dotpath/MongoCompoundEmbeddedPathIndexCreationSpec.groovy Integration test for compound index dot-path field.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/compound/collectionpath/MongoCompoundEmbeddedCollectionPathIndexCreationSpec.groovy Integration test for compound index on collection/multikey field.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/comment/MongoIndexCommentCreationSpec.groovy Integration test for index creation with comment.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/collation/MongoCollationIndexCreationSpec.groovy Integration test for index creation with collation.
data-mongodb/src/test/groovy/io/micronaut/data/mongodb/index/clustered/MongoClusteredCollectionCreationSpec.groovy Integration test for clustered collection creation.
data-mongodb/src/test/groovy/io/micronaut/data/document/mongodb/MongoTestPropertyProvider.groovy Updates default test scanning packages used by Mongo tests.
data-mongodb/src/test/groovy/io/micronaut/data/document/mongodb/MongoIndexInspector.groovy Adds test utility for listing normalized MongoDB index metadata.
data-mongodb/src/test/groovy/io/micronaut/data/document/mongodb/MongoEmbeddedSpec2.groovy Adjusts package scanning list to align with updated test provider defaults.
data-mongodb/src/main/java/io/micronaut/data/mongodb/init/MongoReactiveCollectionsCreator.java Adds index/collection options support and index reconciliation for reactive driver.
data-mongodb/src/main/java/io/micronaut/data/mongodb/init/MongoCollectionsCreator.java Adds index/collection options support and index reconciliation for sync driver.
data-mongodb/src/main/java/io/micronaut/data/mongodb/conf/MongoDataConfiguration.java Adds create-indexes + failure policy configuration and updates error message.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoWildcardIndexes.java Adds container annotation for repeatable top-level wildcard indexes.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoWildcardIndexed.java Adds field-level wildcard index annotation.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoWildcardIndex.java Adds top-level wildcard index annotation.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoTextIndexed.java Adds field-level text index annotation.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoIndexed.java Adds field-level simple index annotation (incl. TTL, collation, etc.).
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoIndexDirection.java Adds Mongo index direction enum.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoHashedIndexed.java Adds field-level hashed index annotation.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoGeoIndexType.java Adds enum of supported geo index types (2d/2dsphere).
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoGeoIndexed.java Adds field-level geo index annotation (incl. bits/min/max/sphereVersion).
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoCompoundIndexField.java Adds annotation describing a compound-index field (incl. geo options).
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoCompoundIndexes.java Adds container annotation for repeatable compound indexes.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoCompoundIndex.java Adds entity-level compound index annotation.
data-mongodb/src/main/java/io/micronaut/data/mongodb/annotation/index/MongoClusteredIndex.java Adds clustered-collection options annotation (incl. clustered TTL).
data-model/src/main/java/io/micronaut/data/annotation/JsonView.java Fixes Javadoc escaping for annotations in documentation snippet.
.github/workflows/gradle.yml Updates workflow branch triggers.
.github/workflows/graalvm-latest.yml Updates workflow branch triggers.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
11 New Critical Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@radovanradic radovanradic requested review from dstepanov and msupic April 2, 2026 13:23

List<String> getPackageNames() {
['io.micronaut.data']
['io.micronaut.data.document.mongodb', 'io.micronaut.data.document.tck.entities']
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated entities for index testing since some have invalid definitions so for indexes different set of packages will be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants