zoukankan      html  css  js  c++  java
  • MongoDB使用

    登录MongoDB
     
    [root@oracle11g ~]# mongo
     
    MongoDB shell version: 2.4.9
    connecting to: test
     
    > use admin
     
    switched to db admin
     
    > show dbs
     
    admin   (empty)
    local   0.078125GB
     
     
    使用新的数据库my_mongodb
     
    > use my_mongodb
     
    switched to db my_mongodb
     
     
    插入三条数据
     
    > db.user.insert({uid:1,username:"Tom",age:25});
    > db.user.insert({uid:2,username:"Jerry",age:25});
    > db.user.insert({uid:1,username:"oracle",age:30});
     
    向数据库my_mongodb的表user中插入了2条记录。MongoDB会隐式的创建数据库my_mongodb和表user
     
     
    查看当前数据库
     
    > show dbs
     
    admin   (empty)
    local   0.078125GB
    my_mongodb      0.203125GB
     
     
    查看当前连接
     
    > show collections
     
    system.indexes
    user
     
     
    查看user表中的数据
     
    > db.user.find();
     
    { "_id" : ObjectId("55823677108162d31a1af236"), "uid" : 1, "username" : "Tom", "age" : 25 }
    { "_id" : ObjectId("55823696108162d31a1af237"), "uid" : 2, "username" : "Jerry", "age" : 25 }
    { "_id" : ObjectId("558236c0108162d31a1af238"), "uid" : 1, "username" : "oracle", "age" : 30 }
     
     
    查找usernameJerry的数据
     
    > db.user.find({username:"Jerry"});
     
    { "_id" : ObjectId("55823696108162d31a1af237"), "uid" : 2, "username" : "Jerry", "age" : 25 }
     
     
    更新uid2age 100
     
    > db.user.update({uid:2},{$set:{age:100}}) ;
     
     
    检查数据是否更新成功
     
    > db.user.find({uid:2});
     
    { "_id" : ObjectId("55823696108162d31a1af237"), "uid" : 2, "username" : "Jerry", "age" : 100 }
     
  • 相关阅读:
    flutter 布局
    常见错误
    xpath
    bzoj1485 [HNOI2009]有趣的数列 卡特兰数
    博弈 Nim问题 POJ2234
    bzoj 1014 [JSOI2008]火星人prefix
    codevs 1743 反转卡片 rope or splay
    bzoj 2326 矩阵乘法
    bzoj 1702 贪心,前缀和
    bzoj 1700 Problem Solving 解题 dp
  • 原文地址:https://www.cnblogs.com/iyoume2008/p/9814624.html
Copyright © 2011-2022 走看看