PHP MongoDB Operation Example

Source: Internet
Author: User
Tags php mongodb

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

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.