File: mongocollection-createindex-options-28.phpt

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (88 lines) | stat: -rw-r--r-- 2,377 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--TEST--
MongoCollection::createIndex() options
--SKIPIF--
<?php $needs = "2.7.0"; $needsOp = "gt"; ?>
<?php require_once "tests/utils/standalone.inc"; ?>
--FILE--
<?php
require_once "tests/utils/server.inc";
$m = mongo_standalone();
$name = dbname();
$colName = 'indexTest';
$d = $m->$name;
$ns = "$name.$colName";
$c = $d->$colName;

$c->drop();

function createResults($result)
{
    if ( $result === NULL ) {
        return;
    }
    echo $result['ok'] ? "OK\n" : "ERR\n";
}

function dropResults($result)
{
    if ( $result === NULL ) {
        return;
    }
    echo $result['ok'] ? 'OK  ' : 'ERR ';
    if ( array_key_exists( 'errmsg', $result ) ) {
        echo $result['errmsg'];
    }
    echo "\n";
}

function showIndexes($res)
{
    echo "Indexes:\n";
    foreach ( $res as $index ) {
        echo ' - ', $index['name'], ': ';
		if (array_key_exists( 'unique', $index ) && $index['unique'] == true ) {
			echo "unique ";
		}
		if (array_key_exists( 'sparse', $index ) && $index['sparse'] == true ) {
			echo "sparse ";
		}
		if (array_key_exists( 'expireAfterSeconds', $index ) ) {
			echo "expireAfterSeconds({$index['expireAfterSeconds']}) ";
		}
        echo json_encode( $index['key'] ), "\n";
    }
}

createResults( $c->ensureIndex( array( "indexE1" => 1 ), array( 'unique' => 1 )) );
createResults( $c->createIndex( array( "indexC1" => 1 ), array( 'unique' => 1 )) );

createResults( $c->ensureIndex( array( "indexE3" => 1 ), array( 'sparse' => 1 )) );
createResults( $c->createIndex( array( "indexC3" => 1 ), array( 'sparse' => 1 )) );

createResults( $c->ensureIndex( array( "indexE4" => 1 ), array( 'expireAfterSeconds' => 42 )) );
createResults( $c->createIndex( array( "indexC4" => 1 ), array( 'expireAfterSeconds' => 43 )) );

createResults( $c->ensureIndex( array( "indexE5" => 1 ), array( 'name' => 'index_E_five' )) );
createResults( $c->createIndex( array( "indexC5" => 1 ), array( 'name' => 'index_C_five' )) );

showIndexes($d->system->indexes->find( array('ns' => $ns) ));
?>
--EXPECT--
OK
OK
OK
OK
OK
OK
OK
OK
Indexes:
 - _id_: {"_id":1}
 - indexE1_1: unique {"indexE1":1}
 - indexC1_1: unique {"indexC1":1}
 - indexE3_1: sparse {"indexE3":1}
 - indexC3_1: sparse {"indexC3":1}
 - indexE4_1: expireAfterSeconds(42) {"indexE4":1}
 - indexC4_1: expireAfterSeconds(43) {"indexC4":1}
 - index_E_five: {"indexE5":1}
 - index_C_five: {"indexC5":1}