_id not displayed as an option when creating a compound index in Compass

I was trying to create a compound index with 2 fields: “tasks” and “_id”. However, to my surprise, the _id is not listed as an option in the dropdown in the Create Index modal. This made me wonder: is using _id in a compound index discouraged by mongodb? is it an anti pattern? or is it just a bug in Compass?
Screenshot 2024-06-14 at 15.14.06

Hi Mateus! Thank you for your question!

The _id must be at the bottom of the dropdown. If you don’t see it, type _id in the input field. If that still doesn’t work, try updating Compass to the latest version or using the MongoDB Shell.

May I ask what is the query that you want to cover with this index?

1 Like

Hi Stanimira.

I’m on Compass’s latest version(1.43.4) and I can confirm the _id is not displayed anywhere in the list. The query is { tasks: { $in: taskIds }, _id: { $ne: routePlan._id }}.
Screenshot 2024-07-22 at 10.50.43

Manually type it into the input field then.

Also be cautious when creating compound indexes with an array field (taskIds), as the index size might be larger than expected. If the array field contains fewer than a couple of hundred items, you should be fine.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.