Morphia not applying sparse option to my index

大城市里の小女人 提交于 2019-12-13 05:14:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!