• NoSQL(二)


    十一、MongoDB数据管理

    >show collections //查看集合,或者使用show  tables
    >db.Account.insert({AccountID:1,UserName:"123",password:"123456"})  //如果集合不存在,直接插入数据,则mongodb会自动创建集合
    >db.Account.update({AccountID:1},{"$set":{"Age":20}}) //更新
    >db.Account.find()   //查看所有文档
    >db.Account.find({AccountID:1})   //根据条件查询
    >db.Account.remove({AccountID:1})  //根据条件删除
    >db.Account.drop() //删除所有文档,即删除集合
    >use dbname  //先进入对应的库
    >db.printCollectionStats()  // 然后查看集合状态

    十二、PHP连接MongoDB-mongodb.so

    cd /usr/local/src/
    yum install -y git
    git clone https://github.com/mongodb/mongo-php-driver
    cd mongo-php-driver
    git submodule update --init  //初始化子模板
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config(yum -y install re2c)

    若出错

    cd /usr/local/src/   //下载mongodb扩展源码包
    wget https://pecl.php.net/get/mongodb-1.3.0.tgz
    tar -zxvf mongodb-1.3.0.tgz
    cd mongodb-1.3.0
    yum install -y php php-devel
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/bin/php-config
    make && make install
    vi /usr/local/php/etc/php.ini  //增加 extension = mongodb.so
    /usr/local/php/bin/php -m

    十三、PHP连接MongoDB mongo.so

    cd /usr/local/src/   //下载mongodb扩展源码包
    wget https://pecl.php.net/get/mongodb-1.3.0.tgz
    tar -zxvf mongodb-1.3.0.tgz
    cd mongodb-1.3.0
    yum install -y php php-devel
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/bin/php-config
    make && make install
    vi /usr/local/php/etc/php.ini  //增加 extension = mongodb.so
    /usr/local/php/bin/php -m

    十四、测试mongo扩展

    vi /usr/local/apache2.4/htdocs/1.php //增加

    <?php
    $m = new MongoClient(); // 连接
    $db = $m->test; // 获取名称为 "test" 的数据库
    $collection = $db->createCollection("runoob");
    echo "集合创建成功";
    ?>

     curl  localhost/1.php

  • 相关阅读:
    编辑器、编译器、文件、IDE等常见概念辨析
    二叉排序树的实现
    模板
    Codeforces Round #690 (Div. 3)
    Educational Codeforces Round 100 (Rated for Div. 2)
    Codeforces 414-B. Mashmokh and ACM(数位dp)
    Codeforces 339D-Xenia and Bit Operations(线段树)
    Educational Codeforces Round 96 (Rated for Div. 2) 题解
    2019-2020 ICPC Northwestern European Regional Programming Contest (NWERC 2019)
    2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)
  • 原文地址:https://www.cnblogs.com/sxt0103/p/14376584.html
Copyright © 2020-2023  润新知