MongoDb-ORM操作,依赖\x\MongoDb
组件实现。
示例:
$Mongo = new \x\MongoDb();
$Mongo->table('user')->dropDatabase();
成功返回true
,失败返回false
。
示例:
$Mongo = new \x\MongoDb();
$Mongo->table('user')->name('log')->dropTable();
成功返回true
,失败返回false
。
示例:
$Mongo = new \x\MongoDb();
// 删除某个索引[单个]
$Mongo->table('user')->name('log')->dropIndex('age');
// 删除某个索引[多个]
$Mongo->table('user')->name('log')->dropIndex(['age','name']);
// 删除全部索引
$Mongo->table('user')->name('log')->removeIndex();
成功返回true
,失败返回false
。
示例:
$Mongo = new \x\MongoDb();
// 添加索引[单条]
$Mongo->table('user')->name('log')->createIndex('age', 'index');
// 添加索引[复合]
$Mongo->table('user')->name('log')->createIndex([
'age' => 'index',
'name' => 'text',
]);
成功返回true
,失败返回false
。
参数要求:
单条索引:createIndex(字段名,索引类型)
多条索引:
createIndex([
字段名 => 索引类型
])
示例:
$Mongo = new \x\MongoDb();
$Mongo->table('user')->name('log')->listIndexe();
成功返回二维数组
,失败返回false
。
成功返回值示例:
array(3) {
[0]=>
array(2) {
["field"]=>
string(3) "_id"
["type"]=>
string(4) "_id_"
}
[1]=>
array(2) {
["field"]=>
string(3) "age"
["type"]=>
string(5) "index"
}
[2]=>
array(2) {
["field"]=>
string(4) "name"
["type"]=>
string(4) "text"
}
}
字段说明:
field
:索引字段名称
type
:索引类型