If we had documents in the cars collection like this:
[
{
"_id": "123abc",
"color": "red",
"make": "Honda"
},
{
"_id": "456xyz",
"color": "blue",
"make": "Toyota"
}
]
Primary Indices will look like this
Key Pattern: ${collectionName}::${property}=${propertyValue}::${primaryKeyValue}
So a concrete example from the above will look like this:
cars::_id="123abc"::123abc => {
"_id": "123abc",
"color": "red",
"make": "Honda"
}
cars::_id="456xyz"::456xyz => {
"_id": "456xyz",
"color": "blue",
"make": "Toyota"
}
Then if we create a secondary index on the "make", we will add two more keys
cars::_id="123abc"::123abc => {...}
cars::_id="456xyz"::456xy => {...}
cars::make="Toyota"::123abc => Ø
cars::make="Honda"::456xy => Ø
Secondary index values are already stored in the key. So no necessity in putting anything in the value.
So when a query comes in looking for "cars.make == 'Honda"
,
it'll loop over all the secondary indices first sees which values match,
pluck their primary keys and do another lap around the collection to get the actual JSON values
One thought triggered by our other discussions - depending on other iterations and searching, building a key that starts with
make
and ends with_id
may want to have other fields in the middle.