First, the application scene: Find MongoDB news name is not "", also not NULL news name, and according to the Heat rankings:
$map [' title '] = Array (' $not ' =>array (' $in ' =>array ("", null));
$news = $this->where ($map)->order (' Value desc ')->field ("Title,class")->select ();
If you want to get a category ranking:
$res =array ();
foreach ($news as $k) {
Array_push ($res, $k [' title ']);
}
$rank =array_search ($this _news[' title '), $res) +1;
If you don't want order rankings, how do you rank the results of a select?
Array_multisort (Array_column ($news, ' value '), Sort_desc, $news);
Second, MongoDB fuzzy query
The Public Function Search_result ($kw) {//Fuzzy query search results
$where [' title '] = Array (' like ', $kw);
$results = $this->where ($where)->order ("Value desc")->select ();
return $results;
}
Third, update the number of views in the site
Public function Update_seen ($id) {//Update site views $arr =[$id, 0];
$querys = Array ("_id" =>array (' $in ' => $arr)); Why do I write this, not directly $querys[' _id ']= $id, because the _id of the database I'm connecting to is not the MongoDB database automatically generated, but we customize it, and when you're using $querys[' _id ',
Thinkphp will automatically turn your $id into Objectid form, but $id itself cannot be converted to Objectid, causing an error $news = $this->where ($querys)->find ();
if ($news) {$seen = $news [' Seen ']+0;
if ($seen ==null or! $seen) {$seen = 0;
$data [' Seen ']= $seen +1;
$querys = Array ("_id" =>array (' $in ' => $arr));
$this->where ($querys)->save ($data); }
}