Enums in MongoDB

后端 未结 1 1844
面向向阳花
面向向阳花 2020-12-18 18:12

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 Mon

相关标签:
1条回答
  • 2020-12-18 18:38

    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.

    0 讨论(0)
提交回复
热议问题