Indexes speed up queries and sorts by letting PostgreSQL find documents without scanning the whole table. Rango creates them as native PostgreSQL indexes on the JSONB data column, so you keep MongoDB-style ergonomics with PostgreSQL performance.
Pass a key map to createIndex, where each field maps to 1 for ascending or -1 for descending order:
$collection->createIndex(['email' => 1]);
$collection->createIndex(['age' => -1, 'name' => 1]);Use the unique option to enforce uniqueness, and name to choose the index name. Without a name, Rango derives one from the database, collection, and fields:
$collection->createIndex(['email' => 1], ['unique' => true, 'name' => 'users_email_unique']);Index the fields you filter and sort on most often, such as the keys you pass to find and the sort option.
listIndexes returns an iterator of IndexInfo objects describing the indexes on the collection:
foreach ($collection->listIndexes() as $index) {
echo $index->getName();
$index->getKey(); // ['email' => 1]
$index->isUnique(); // true or false
}Drop an index by name:
$collection->dropIndex('users_email_unique');Geospatial, text, sparse, and TTL indexes are not supported. The matching IndexInfo checks always report false, as listed under limitations.