Questions about indexes for Boolean fields - MongoDB

0

I have documents with boolean fields in a Mongo collection. To index these fields, is it better for their values to be Number (0 or 1) or does it make no difference if they are Boolean? I have received some "slow query" alerts in the search by using these Boolean fields.

    
asked by anonymous 28.12.2017 / 23:04

1 answer

1

In the end, the index will have two entries (0 and 1 or true and false), and I think it will not make any difference. No doubt Boolean values will take up less disk space, which will leave you with a smaller index and smaller data.

Slow lookups should be for another reason. Do you have more filters in the query besides this boolean field? in what order did you create the index fields? Do you have an order in the query? Add an example query that went slow, and shows the structure of your document that is easier to help.

    
29.12.2017 / 11:26