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
|
--TEST--
MongoCollection::ensureIndex() (scalar field/array of fields)
--SKIPIF--
<?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'], ': ';
echo json_encode( $index['key'] ), "\n";
}
}
$i = new stdClass;
$i->indexE1 = 1;
createResults( $c->ensureIndex( $i ) );
$i = new stdClass;
$i->indexC1 = -1;
createResults( $c->ensureIndex( $i ) );
$i = new stdClass;
$i->indexC3 = '2d';
$i->indexC2 = -1;
createResults( $c->ensureIndex( $i ) );
showIndexes($d->system->indexes->find( array('ns' => $ns) ));
?>
--EXPECT--
OK
OK
OK
Indexes:
- _id_: {"_id":1}
- indexE1_1: {"indexE1":1}
- indexC1_-1: {"indexC1":-1}
- indexC3_2d_indexC2_-1: {"indexC3":"2d","indexC2":-1}
|