欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PHP MongoDB-创建索引(create index)

程序员文章站 2022-07-09 09:35:00
...

1、php-mongodb代码建索引(createIndexes):

<?php
    $manager = new \MongoDB\Driver\Manager("mongodb://admin:[email protected]:27017");
    $command = new MongoDB\Driver\Command([
      "createIndexes" => "collectionName",
      "indexes"       => [[
        "name" => "indexName",
        "key"  => [ "keyName" => 1],
        "ns"   => "databaseName.collectionName",
     ]],
  ]);
  $result = $manager->executeCommand("databaseName", $command);
?>

 

 

2、php-mongodb代码删除集合(drop):

<?php
  $manager = new \MongoDB\Driver\Manager("mongodb://admin:[email protected]:27017");
  $command = new MongoDB\Driver\Command([
    "drop" => "collectionName",
  ]);
  $result = $manager->executeCommand("databaseName", $command);
?>

 

 

3、php-mongodb代码创建集合(create):

<?php
  $manager = new \MongoDB\Driver\Manager("mongodb://admin:[email protected]:27017");
  $command = new MongoDB\Driver\Command([
    "create" => "collectionName",
  ]);
  $result = $manager->executeCommand("databaseName", $command);
?>