Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for Wildcard Index #3671

Closed
wants to merge 2 commits into from
Closed

Add support for Wildcard Index #3671

wants to merge 2 commits into from

Conversation

christophstrobl
Copy link
Member

@christophstrobl christophstrobl commented Jun 16, 2021

A WildcardIndex is an index that can be used to include all fields or specific ones based a given (wildcard) pattern.

The index can be set up programmatically using WildcardIndex via IndexOperations.

mongoOperations
    .indexOps(User.class)
    .ensureIndex(new WildcardIndex("userMetadata"));
db.user.createIndex({ "userMetadata.$**" : 1 }, {})

The @WildcardIndex annotation allows a declarative index setup and can be added on either a type or property.

If placed on a type that is a root level domain entity (one having an @Document annotation) will advise the index creator to create a wildcard index for it.

@Document
@WildcardIndexed
public class Product {
    ...
}
db.product.createIndex({ "$**" : 1 },{})

The wildcardProjection can be used to specify keys to in-/exclude in the index.

@Document
@WildcardIndexed(wildcardProjection = "{ 'userMetadata.age' : 0 }")
public class User {
    private @Id String id;
    private UserMetadata userMetadata;
}
```javascript
db.user.createIndex(
  { "$**" : 1 },
  { "wildcardProjection" :
    { "userMetadata.age" : 0 }
  }
)

Wildcard indexes can also be expressed by adding the annotation directly to the field.
Please note that wildcardProjection is not allowed on nested paths.

@Document
public class User {
    private @Id String id;

    @WildcardIndexed
    private UserMetadata userMetadata;
}
db.user.createIndex({ "userMetadata.$**" : 1 }, {})

Closes: #3225

via the declarative WildcardIndexed annotation and the programatic WildcardIndex.
@mp911de mp911de self-assigned this Jul 12, 2021
@mp911de mp911de added this to the 3.3 M1 (2021.1.0) milestone Jul 14, 2021
@mp911de mp911de added the type: enhancement A general enhancement label Jul 14, 2021
mp911de pushed a commit that referenced this pull request Jul 14, 2021
Add WildcardIndexed annotation and the programatic WildcardIndex.

Closes #3225
Original pull request: #3671.
mp911de added a commit that referenced this pull request Jul 14, 2021
Reformat code. Tweak javadoc. Reject wildcard projection usage on properties with a MappingException. Omit wildcard projections when declared on document types that are used as subdocument.

See #3225
Original pull request: #3671.
@mp911de
Copy link
Member

mp911de commented Jul 14, 2021

That's merged and polished now.

@mp911de mp911de closed this Jul 14, 2021
@mp911de mp911de deleted the issue/3225 branch September 21, 2021 13:00
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Wildcard Indexes [DATAMONGO-2368]
2 participants