Sokil\Mongo\Collection::ensureTTLIndex PHP 메소드

ensureTTLIndex() 공개 메소드

Create TTL index
public ensureTTLIndex ( array $key, integer $seconds ) : Collection
$key array key must be date to use TTL
$seconds integer
리턴 Collection
    public function ensureTTLIndex(array $key, $seconds = 0)
    {
        $this->getMongoCollection()->createIndex($key, array('expireAfterSeconds' => $seconds));
        return $this;
    }

Usage Example

예제 #1
0
 public function testEnsureTTLIndex()
 {
     $this->collection->ensureTTLIndex(array('ttlAsc' => 1, 'ttlDesc' => -1), 12000);
     $indexes = $this->collection->getIndexes();
     $this->assertEquals(array('ttlAsc' => 1, 'ttlDesc' => -1), $indexes[1]['key']);
     $this->assertArrayHasKey('expireAfterSeconds', $indexes[1]);
     $this->assertEquals(12000, $indexes[1]['expireAfterSeconds']);
 }