1.以某字段开头的数据查询条件
$title = input('param.title');
$where['title'] = new MongoDBBSONRegex("^{$title}",'i'); //已title开头的字
2.原生用法:
//query 查询列表
$command = new MongoDBDriverQuery($where);
$manager = new MongoDBDriverManager('mongodb://localhost:27017');
$lists = $manager->executeQuery("news.friend_circle", $command);
var_dump($lists->toArray());
//command用法
$command = new MongoDBDriverCommand($document);
var_dump($command);
$list = $mongoModel->Command($command,"friend_circle");
var_dump($list);
3.根据某字段模糊查询
1)命令行:db.news_live.find({"title":/测试?/i});
2)代码查询$query
=
array
(
"name"
=>
new
MongoRegex(
"/.*”.$name."
.*/i"));
3.根据数据库某字段排序(比如根据时间排序)
$order = array('create_time'=>-1); //-1表示降序,1表示升序
$list = $mongo->order($order)->select();