zoukankan      html  css  js  c++  java
  • PHP 关于MongoDB的操作

    <?php
    header("Content-type:text/html;charset=utf-8");
    $m = new MongoClient(); // 连接
    $db = $m->test; // 获取名称为 "test" 的数据库
    /*集合创建成功
    $collection = $db->createCollection("runoob");
    echo "集合创建成功";*/
    
    
    /*插入
    $collection = $db->runoob; // 选择集合
    $document = array( 
    "title" => "MongoDB", 
    "description" => "database", 
    "likes" => 100,
    "url" => "http://www.runoob.com/mongodb/",
    "by", "菜鸟教程"
    );
    $collection->insert($document);
    echo "数据插入成功";*/
    
    /*查询
    $collection = $db->runoob; // 选择集合
    
    $cursor = $collection->find();
    // 迭代显示文档标题
    foreach ($cursor as $document) {
    echo $document["title"] . "
    ";
    }*/
    
    /*更新
    $collection = $db->runoob; // 选择集合
    // 更新文档
    $collection->update(array("title"=>"MongoDB"), array('$set'=>array("title"=>"MongoDB 教程")));
    // 显示更新后的文档
    $cursor = $collection->find();
    // 循环显示文档标题
    foreach ($cursor as $document) {
    echo $document["title"] . "
    ";
    }*/
    
    /*删除
    $collection = $db->runoob; // 选择集合
    $collection->remove(array("title"=>"MongoDB 教程"), array("justOne" => true));
    
    // 显示可用文档数据
    $cursor = $collection->find();
    foreach ($cursor as $document) {
    echo $document["title"] . "
    ";
    }*/
    
    ?>
  • 相关阅读:
    引入RabbitMQ后,如何保证全链路数据100%不丢
    使用logstash迁移elasticsearch
    内网代理转发工具
    MSSQL存储过程命令执行
    win10 家庭版升级专业版密钥
    clash TUN模式
    windows实战常用命令
    webshell之jsp免杀
    tmux的使用方法
    钓鱼邮件从入门到放弃
  • 原文地址:https://www.cnblogs.com/mracale/p/5715411.html
Copyright © 2011-2022 走看看