PHP code example of since / mongo

1. Go to this page and download the library: Download since/mongo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

since / mongo example snippets


use since\mongo;
t
  $mongo=new MongoDB();
 //可以自定义参数
  $config = [
        'host' => '127.0.0.1',
        "port" => 27017,
        "username" => "",
        "password" => "",
        "database" => "test"
    ]
    $mongo=new MongoDB($config);

  //新增一条
 $document = array(
                "name" => "John",
                "age" => 16,
                "sex" => 1
            );
  $mongo->table("user")->insert($document);
 //新增多条
            $document = [
                array(
                    "name" => "john",
                    "age" => 16,
                    "sex" => 1
                ),array(
                    "name" => "tom",
                    "age" => 18,
                    "sex" => 1
                ),array(
                    "name" => "lucy",
                    "age" => 18,
                    "sex" => 2
                )];
        $res=$mod->table("user")->insertAll($document);
   //或者     
   $res=$mod->table("user")->insert($document,true);