Sparse indexes only contain entries for documents that have the indexed
field, even if the index field contains a null value. The index skips
over any document that is missing the indexed field.
public ensureSparseIndex ( array $key ) : |
||
$key | array | An array specifying the index's fields as its keys. For each field, the value is either the index direction or index type. If specifying direction, specify 1 for ascending or -1 for descending. |
return |
public function testEnsureSparseIndex() { $this->collection->ensureSparseIndex(array('sparseAsc' => 1, 'sparseDesc' => -1)); $indexes = $this->collection->getIndexes(); $this->assertEquals(array('sparseAsc' => 1, 'sparseDesc' => -1), $indexes[1]['key']); $this->assertArrayHasKey('sparse', $indexes[1]); }