The Wildcard Index should be the preferred choice over the Attribute Pattern if you are using MongoDB 4.2.
That said, there are some relationships that can be “enhanced” or “qualified” by using the Attribute Pattern.
For example, let’s say that I have the following:
{
"veteran_discount": 18
"price": 20.99
}
And I decided to apply the Attribute Pattern, resulting in:
{
attributes: [
{ "k": "veteran_discount", "v": 18 },
{ "k": "price", "v": 20.99 },
]
}
I may decide that some relationships may need more information, for example keeping track of the currency for the price, resulting in:
{
attributes: [
{ "k": "veteran_discount", "v": 18 },
{ "k": "price", "currency": "euros", "v": 20.99 },
]
}
Again, the Wildcard Index simplifies a lot and let you keep the documents in a more natural form, but keep in the back of your mind what the Attribute Pattern could do for you.
Regards,
Daniel