Are there any reason to use Integer enum values outside of validation on creation? I can’t databind the values to an integer value, sort on value or use number features in table. It seems enum values defaults to sorting on created date. Does it function exactly the same as the string enum value other than on creation validation?
Hi, Lavrans
Good question!
The String/Integer type is good for external system compatibility and human readability.
Especially when you need to:
-
Send/receive data to systems expecting integer codes (e.g.,
1, 2, 3) -
Match foreign keys in external databases
-
Integrate with legacy systems using numeric identifier
If you’re not integrating with external systems that specifically require integer codes, there is no specific upside to using String/Integer over Auto other than personal preference.
Hi, Nikoline!
Thank you for your answer. It seems like they are handled like strings either way, so this would still work if I made String the datatype and only added numbers as values?
Are there any at-scale advantages for storing the values as integers rather than strings? If so, when would this practically have an impact?
What is the reason for the values to not be treated as integers in appfarm? For example in sorting of priority it would be very practical
It would still work if you made String the datatype and only added numbers, given you treat them as such. If you were to do some mathematical operation on the values, you would need to convert the String numbers to Int first.
Integers are the most “efficient” datatype to use if you were to have a big amount of data. An empty String is 5 bytes, and a 32-bit Int is 4 bytes(Auto is saved as an ObjectID and is 12 bytes). If you were to e.g. read or do operations on large amounts of data based on a String or Int enum value, the Int value would be more efficient.
The sorting based on enum values in the UI is not implemented. You could read objects using aggregate to sort them based on your enum. Another workaround would be to create your enum with values in ascending order. I will register a challenge on this.


