MongoDB中的枚举 [英] Enums in MongoDB
问题描述
将MongoDB中的枚举值存储为字符串是完全正确的,是的,如果您索引字段,我希望性能可以与索引整数查询相当。这比使用整数更有表现力。
唯一真正的缺点是,如果你的枚举字符串有点长,那么它们会占用更多的空间,但这是一个很小的问题。
I want to store enum values in MongoDB collection. Can I effectively store them as strings? Will it affect index performance in comparison with enum values as ints? Does Mongo indexer optimize string indexes in the case when they contain only few fixed options as string values, to achieve speed similar to querying index by sorted integer?
Storing enum values in MongoDB as strings is perfectly fine, and yes, if you index the field I'd expect the performance to be comparable to indexed integer queries. It's certainly more expressive than using integers.
The only real downside is that they'll take more space if your enum strings are somewhat long, but that's a pretty trivial concern.
这篇关于MongoDB中的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!