问题
I'm trying to use Morphia to interface with MongoDB, and my Morphia entity looks like this:
@Entity(some params about storing the entity)
public class Entity implements Serializable {
<Some other fields here>
@Indexed(options =
@IndexOptions(unique = true, sparse = true)
)
private String field;
<Some other fields here>
}
I would like this field to be unique if present, but not required (and not unique if not present; multiple entries should be able to exclude this field). My understanding of how to do this is with a unique sparse index, as I've tried to set up.
The problem I'm running into is that when I check the index configuration in Studio3T, it appears that my index is being created as unique, but the sparse property is not applied.
What am I doing wrong?
Thanks.
EDIT: Upon further research, this appears like it might be an issue with Microsoft Azure CosmosDB. When I run this code locally, it works fine, but it does not create the sparse index properly on Azure CosmosDB. Updating tags accordingly.
来源:https://stackoverflow.com/questions/51884690/morphia-not-applying-sparse-option-to-my-index