Tag:table Settings create doc option results use matching delete
Query
$filter = [' _id ' = = new Mongodb\bson\objectid ("$id"), ' creater_id ' = $user [' user_id '], ' delete_flag ' = ' N ',]; Query conditions $options = [' projection ' + = [' _id ' = + 1, ' id ' = + 1, ' title ' = 1, ' status ' = 1, ' Delete_flag ' + 1], ' limit ' = $page _size, Limit ' skip ' = (int) (($page _index-1) * $page _size),//Skip ' Sort ' = [' create_time ' = 1]//sort]; Action Item $doc = $this->mongo_db->findone (' table ', $filter, $options); Return!empty ($doc)? $doc->getarraycopy (): []; Getarraycopy () to convert the query result to an array
Update
$filter = [ ‘_id‘ => new MongoDB\BSON\ObjectId("$id") // 匹配条件 ]; $options = [ ‘$set‘ => [‘delete_flag‘ => ‘Y‘] // 设置要更新的字段值 ]; $doc = $this->mongo_db->updateOne(‘table‘, $filter, $options); $modified_count = $doc->getModifiedCount(); if ($modified_count == 1) { return true; } // getModifiedCount() 获取被影响行数 // getMatchedCount() 获取查询结果匹配数
Cluster
PHP MongoDB Operation Example