Doubt about Index for Boolean Fields - Mongodb

Asked

Viewed 72 times

0

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

1 answer

1

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

Slow query warnings should be for another reason. Do you have more filters in the query besides this boolean field? in what order you created the index fields? have sorting in the query? Add a query example that’s been slow, and show your document structure that’s easier to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.