Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Indexes: correctly translate partial filter expressions with automatic embedded entity indexes #1290

Closed
d4nirod opened this issue Nov 20, 2018 · 2 comments
Labels
Milestone

Comments

@d4nirod
Copy link

d4nirod commented Nov 20, 2018

If I have en entity FeedEvent with an index such as

@Index(fields = { @Field("actor.actorObject.userId"), @Field(value = "actor.actorType", type = DESC) }, 
  options = @IndexOptions(disableValidation = true, 
    partialFilter = "{ 'actor.actorObject.userId': { $exists: true }, 'actor.actorType': { $exists: true } }")),

And also another entity InboxEvent that has a field called feedEvent, polymorphic, holding subtypes of FeedEvent as @Embedded.

Morphia automagically creates another index here like { feedEvent.actor.actorObject.userId, feedEvent.actor.actorType } which is nice...
BUT it doesn't seem to be handling the partial filter expression correctly, this is, it's creating this automatic index by prepending feedEvent to the fields of the original index but it's not doing the same for the field paths in the partial filter expression so the index is wrong.
If I try to set the index manually in InboxEvent Mongo will complain saying that there's already an index with the same keys but different options.
So the workaround is to remove the original index in FeedEvent and create both manually with the driver.

@evanchooly evanchooly added this to the 1.5.0 milestone Jan 25, 2019
@evanchooly evanchooly added the bug label Jan 25, 2019
@evanchooly
Copy link
Member

I'm going to try to recreate your problem based on what's here but if you could provide me with the index you think you should have, I'll try to get to the bottom of this. Thanks.

@evanchooly
Copy link
Member

OK. I think i have recreated this sufficiently and see what you're talking about. I'm going to dig in to see what it'd take to correct this but, fair warning, i was planning on deprecating the index generation based on @Embedded types in 2.0. Finding nested index definitions and automatically creating indexes on the parent type is error prone and not always desirable. Indexes are about queryability and not all embedded types are meant to be queried. Better to explicitly declare on the top level types what indexes to used on those collections and not overallocate indexes that will never be used but still must be maintained by the server.

At any rate, I'll see if there's something that can be done in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants