String vs. Number Comparison Efficiency in MongoDB

Viewed 3342

Suppose that I querying by an arbitrary field category that will be four characters long with all numbers.

So, it could be '1234', '2341', '9999' etc.

Now, if I am certain that this numerical representation of this string will be greater than or equal to 1000 and less than or equal to 9999, does making this field a number instead of a string make the query more efficient? I believe that number comparisons are more efficient than string comparisons, but I am not sure that it will have any discernible effect on the query performance. I believe that making this field a string would be better if query performance is equal because the field categories number is just an identifier and therefore a string is more descriptive of what is going on, but better query performance is more important.

Therefore, my question is if I query on this arbitrary category field will it be more efficient to query by string or by number or that it doesn't matter?

1 Answers
Related