zoukankan      html  css  js  c++  java
  • MongoDB基本概念

    传统的关系数据库一般由database, table, record三个层次概念组成,MongoDB是由数据库(database), 集合(collection), 文档(document)三个层析组成的。

    1. 安装和配置:

    1. 第一步:下载安装包:http://www.mongodb.org/downloads←单击此处,如果是win系统,注意是64位还是32位版本的,请选择正确的版本。
    2. 第二步:新建目录“D:MongoDB”,解压下载到的安装包,找到bin目录下面全部.exe文件,拷贝到刚创建的目录下。
    3. 第三步:在“D:MongoDB”目录下新建“data”文件夹,它将会作为数据存放的根文件夹。
    4. 打开CMD窗口,按照如下方式输入命令:
        > d:
        > cd D:MongoDB
        > mongod --dbpath D:MongoDBdata
    5. 在浏览器输入:http://localhost:27017/,可以看到如下提示:
      You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number
    6. 如此,MongoDB数据库服务已经成功启动了
    db.test.find({'name':'foobar'}) <==> select * from test where name='foobar'
    db.test.find()                  <==> select * from test
    db.test.find({'ID':10}).count() <==> select count(*) from test where ID=10
    db.test.find().skip(10).limit(20)     <==> select * from test limit 10,20
    db.test.find({'ID':{$in:[25,35,45]}}) <==> select * from test where ID in (25,35,45)
    db.test.find().sort({'ID':-1})        <==> select * from test order by ID desc
    db.test.distinct('name',{'ID':{$lt:20}})  <==> select distinct(name) from test where ID<20
    db.test.group({key:{'name':true},cond:{'name':'foo'},reduce:function(obj,prev){prev.msum+=obj.marks;},initial:{msum:0}})  <==> select name,sum(marks) from test group by name
    db.test.find('this.ID<20',{name:1})  <==> select name from test where ID<20
    db.test.insert({'name':'foobar','age':25})<==>insert into test ('name','age') values('foobar',25)
    db.test.remove({})                <==> delete * from test
    db.test.remove({'age':20})        <==> delete test where age=20
    db.test.remove({'age':{$lt:20}})  <==> elete test where age<20
    db.test.remove({'age':{$lte:20}}) <==> delete test where age<=20
    db.test.remove({'age':{$gt:20}})  <==> delete test where age>20
    db.test.remove({'age':{$gte:20}}) <==> delete test where age>=20
    db.test.remove({'age':{$ne:20}})  <==> delete test where age!=20
    db.test.update({'name':'foobar'},{$set:{'age':36}}) <==> update test set age=36 where name='foobar'
    db.test.update({'name':'foobar'},{$inc:{'age':3}})  <==> update test set age=age+3 where name='foobar'

    注意以上命令大小写敏感

  • 相关阅读:
    java方法执行超时关闭
    PostGIS-将多面转换为单面(PostGIS
    deepin安装JDK
    Power Designer反向工程
    【Redis实操】twemproxy代理搭建
    mysql 一些语句
    利用insertd查出更新记录
    sqlserver 存储过程分页
    sqlserver存储过程分页记录
    js group by
  • 原文地址:https://www.cnblogs.com/lindsayzhao103011/p/3443576.html
Copyright © 2011-2022 走看看