本文整理汇总了PHP中MongoCollection::createIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::createIndex方法的具体用法?PHP MongoCollection::createIndex怎么用?PHP MongoCollection::createIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::createIndex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Note that we use TTL Collections to have the Mongo deamon automatically clean
* expired entries.
*
* @link http://docs.mongodb.org/manual/tutorial/expire-data/
* @param array $options
*/
public function __construct(array $options = array())
{
if (!extension_loaded('mongo')) {
Zend_Cache::throwException('The MongoDB extension must be loaded for using this backend !');
}
parent::__construct($options);
// Merge the options passed in; overriding any default options
$this->_options = array_merge($this->_options, $options);
$conn = new \MongoClient($this->_getServerConnectionUrl());
$this->_database = $conn->{$this->_options['dbname']};
$this->_collection = $this->_database->selectCollection($this->_options['collection']);
$this->_collection->createIndex(array('tags' => 1), array('background' => true));
$this->_collection->createIndex(array('expires_at' => 1), array('background' => true, 'expireAfterSeconds' => 0));
}
示例2: index
/**
* Specify an index for the collection.
*
* @param string|array $columns
* @param array $options
* @return Blueprint
*/
public function index($columns = null, $options = [])
{
$columns = $this->fluent($columns);
// Columns are passed as a default array.
if (is_array($columns) && is_int(key($columns))) {
// Transform the columns to the required array format.
$transform = [];
foreach ($columns as $column) {
$transform[$column] = 1;
}
$columns = $transform;
}
$this->collection->createIndex($columns, $options);
return $this;
}
示例3: postUp
public function postUp(Schema $schema)
{
$upgradeHelper = new UpgradeHelper($this->container);
if ($upgradeHelper->areProductsStoredInMongo()) {
$database = $upgradeHelper->getMongoInstance();
$tableHelper = new SchemaHelper($this->container);
echo "Add index to Version document on column loggetAt...\n";
$versionCollection = new \MongoCollection($database, $tableHelper->getTableOrCollection('version'));
$versionCollection->createIndex(['loggedAt' => -1], ['background' => true]);
echo "Done.";
}
}
示例4: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
set_time_limit(0);
$db = \DB::getMongoDB();
$statementsCollection = new MongoCollection($db, 'statements');
$statementsCollection->createIndex(['stored' => 1], ['background' => 1, 'socketTimeoutMS' => -1]);
$statementsCollection->createIndex(['stored' => -1], ['background' => 1, 'socketTimeoutMS' => -1]);
$statementsCollection->createIndex(['lrs_id' => 1, 'stored' => 1], ['background' => 1, 'socketTimeoutMS' => -1]);
$statementsCollection->createIndex(['lrs_id' => 1, 'stored' => -1], ['background' => 1, 'socketTimeoutMS' => -1]);
$statementsCursor = $statementsCollection->find();
$remaining = $statementsCursor->count();
print $remaining . ' statements total' . PHP_EOL;
$maxBatchSize = 10000;
while ($statementsCursor->hasNext()) {
$batch = new MongoUpdateBatch($statementsCollection);
$batchSize = 0;
while ($batchSize < $maxBatchSize && $statementsCursor->hasNext()) {
$batchSize++;
$statement = $statementsCursor->next();
$statementStored = new Carbon\Carbon($statement['statement']['stored']);
$query = ['q' => ['_id' => $statement['_id']], 'u' => ['$set' => ["stored" => new \MongoDate($statementStored->timestamp, $statementStored->micro)]], 'multi' => false, 'upsert' => false];
if (isset($statement['refs'])) {
foreach ($statement['refs'] as $key => $refStatement) {
if (isset($refStatement['timestamp']) && !$refStatement['timestamp'] instanceof MongoDate) {
$timestamp = new Carbon\Carbon($refStatement['timestamp']);
$query['u']['$set']['refs.' . $key . '.timestamp'] = new \MongoDate($timestamp->timestamp, $timestamp->micro);
}
if (isset($refStatement['stored']) && !$refStatement['stored'] instanceof MongoDate) {
$stored = new Carbon\Carbon($refStatement['stored']);
$query['u']['$set']['refs.' . $key . '.stored'] = new \MongoDate($stored->timestamp, $stored->micro);
}
}
}
$batch->add((object) $query);
}
$batch->execute();
$remaining -= $batchSize;
print $remaining . ' remaining' . PHP_EOL;
}
}
开发者ID:learninglocker,项目名称:learninglocker,代码行数:45,代码来源:2015_12_23_093122_add_stored_to_statement_root.php
示例5: MongoCollection
$keys['flatsale'] = ['', 'state', 'city', 'county', 'region', 'aptName', 'area'];
$keys['houserent'] = ['', 'state', 'city', 'county', 'region', 'monthlyType'];
$keys['aptrent'] = ['', 'state', 'city', 'county', 'region', 'aptName', 'area', 'monthlyType'];
$keys['flatrent'] = ['', 'state', 'city', 'county', 'region', 'aptName', 'area', 'monthlyType'];
foreach ($keys as $key => $val) {
echo 'Adding index $key...\\n';
$col = new MongoCollection($db, $key);
$col_agg = new MongoCollection($db, $key . '_agg');
$idx_key = [];
foreach ($val as $id) {
if ($id) {
$idx_key[$id] = 1;
}
$added_idx_key = array_merge($idx_key, ['year' => 1]);
print_r($added_idx_key);
$r = $col->createIndex($added_idx_key);
print_r($r);
$added_idx_key = array_merge($idx_key, ['year' => 1, 'month' => 1]);
$r = $col->createIndex($added_idx_key);
print_r($r);
$added_idx_key = array_merge($idx_key, ['year' => -1, 'month' => -1]);
$r = $col->createIndex($added_idx_key);
print_r($r);
$col->createIndex(['year' => 1, 'month' => 1]);
$col->createIndex(['year' => -1, 'month' => -1]);
$r = $col_agg->createIndex($added_idx_key);
print_r($r);
$col_agg->createIndex(['year' => 1, 'month' => 1]);
$col_agg->createIndex(['year' => -1, 'month' => -1]);
}
}
示例6: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$db = \DB::getMongoDB();
$indexOptions = ['background' => 1, 'socketTimeoutMS' => -1];
$statements = new MongoCollection($db, 'statements');
$statements->createIndex(['statement.id' => 1, 'lrs_id' => 1], $indexOptions);
$statements->createIndex(['statement.actor.mbox' => 1], $indexOptions);
$statements->createIndex(['stored' => 1], $indexOptions);
$statements->createIndex(['timestamp' => 1], $indexOptions);
$statements->createIndex(['active' => 1], $indexOptions);
$statements->createIndex(['voided' => 1], $indexOptions);
$statements->createIndex(['lrs_id' => 1], $indexOptions);
$statements->createIndex(['lrs_id' => 1, 'active' => -1, 'voided' => 1], $indexOptions);
$statements->createIndex(['lrs_id' => 1, 'statement.actor.account.name' => 1, 'statement.actor.account.homePage' => 1], $indexOptions);
$statements->createIndex(['lrs_id' => 1, 'statement.actor.mbox' => 1], $indexOptions);
$statements->createIndex(['lrs_id' => 1, 'statement.verb.id' => 1], $indexOptions);
$statements->createIndex(['lrs_id' => 1, 'statement.object.id' => 1], $indexOptions);
$statements->createIndex(['lrs_id' => 1, 'stored' => -1], $indexOptions);
$statements->createIndex(['lrs_id' => 1, 'timestamp' => -1], $indexOptions);
}
开发者ID:learninglocker,项目名称:learninglocker,代码行数:25,代码来源:2016_05_20_130927_create_statement_indexes.php
示例7: array
function __construct($host = 'localhost', $port = 27017)
{
$this->connection = new \MongoClient('mongodb://' . $host . ':' . $port);
$this->index = $this->connection->search->index;
$this->index->createIndex(array('token' => 1), array('unique' => true));
}
示例8: createIndex
public function createIndex()
{
$this->collection->createIndex(["packageName" => 1, "packageVersion" => 1]);
}
示例9: ensureIndex
public function ensureIndex($fieldName)
{
$this->collection->createIndex([$fieldName => 1]);
}