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"] . "
    ";
    }*/
    
    ?>
  • 相关阅读:
    python迭代器与iter()函数实例教程
    手动安装python后,交互模式下退格键乱码
    find参数exec、管道符|、xargs的区别
    比较好的网址收集
    sed小知识总结
    irc操作小记
    irssi忽略退出,加入消息
    Web自动化简介
    android&ios区别
    移动自动化应用展望
  • 原文地址:https://www.cnblogs.com/mracale/p/5715411.html
Copyright © 2011-2022 走看看