Alex Rivera | Logout

Enums in MongoDB

Asked 2012-11-18T18:33:49.693
38

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?

Edit
Report

1 Answer

33

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.

answered 2012-11-18T19:40:14.337

Your Answer