MongoDB以及MongoVUE的安装和使用

环境安装

MongoDB的安装

到这里mongodb就已经安装成功了。

  • 创建存储数据的文件夹 
    如下图,在D盘下创建一个用于装数据的data文件夹。 

  • 指定数据存储路径并启动服务

    • 在cmd下进入刚刚mongoDB安装的路径,如下图: 
    • 启动服务 
      执行指令:mongod –dbpath D:\data(这里注意前面是两个-,markdown不知道为什么显示出来就只有一个-了,见下图中的指令),其中D:\data为数据存放的位置。如下图这启动成功。 
    • 验证服务是否已经启动 
      在浏览器下打开:http://localhost:27017/,如果出现下图效果则说明服务已经启动成功: 
    • 注意1:在打开MongoVUE之前,一定要先启动MongoDB服务器,否则到时候会出现连接不上的情况(连接不上的时候号可以试试这个方法:引擎不一样,可以切换过引擎,改用mongod --storageEngine mmapv1 --dbpath (data的路径)
      https://sfault-image.b0.upaiyun.com/188/885/1888859868-5a0ec851ab2a4_articlex
    • 注意2:mongod –dbpath D:\data启动指令中的D:\data只是一个例子,这个目录是自己创建的存数据的文件夹
MongoVUE安装
  • 下载MongoVUE 
    个人网盘下载 
    下载解压后效果如下: 

  • 安装 
    如下图: 

    不多做解释,到此MongoVUE已经安装完成.

  • 破解 
    将解压zip下“破解补丁”文件夹中的“MongoVUE.exe”文件替换到安装文件目录下,如下图: 
     
    替换到 
     
    到此,破解已经完成。

建立连接

  • 先打开MongoVUE,按如下图流程 

基础操作

创建表
  • 右键数据库,点击add Collection,如下图: 


添加数据
  • 选择刚刚添加的表,右键,选择Insert/Import Documents,如下图: 

    查看log日志 

    db.Test.insert({
        Name:"张三",
        Age:23,
        Sex:"男",
        Add:"XXX市XXX号XXX街道XXX号"
    });
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

查询
  • 如下图,最基础的查询: 

    • 基本查询,在{find}中输入Json 
      如:{Name:”张三”} 
      db.Test.find({ "Name" : "张三" }).limit(50);
      db.Test.find({ "Name" : "张三" }).limit(50).explain();
      • 1
      • 2

日期查询
  • 需要通过ISODate函数将日期进行格式话,如:{“InsertDate”:ISODate(“2016-03-09T16:00:00Z”)}

    • 查询大于,小于,大于等于,小于等于 

      db.Test.find({ "Age" : { "$gt" : 50 } }).limit(50);
      db.Test.find({ "Age" : { "$gt" : 50 } }).limit(50).explain();
      • 1
      • 2
      \$lt:小于
      \$lte:小于等于
      \$gt:大于
      \$gte:大于等于
      
      • 1
      • 2
      • 3
      • 4
      • 5
    • 右击表格,点击Find2,比Find多了一个where;写表达式,如下图: 

      db.Test.find({ "$where" : "this.Age==23 || this.Age==50" }).limit(50);
      db.Test.find({ "$where" : "this.Age==23 || this.Age==50" }).limit(50).explain();
      • 1
      • 2

排序${Sort}
  • 如下图,在${Sort}中输入Json:{Age:-1},即对Age字段进行排序: 

    注:当大于0的时候为升序,小于0的时候则为降序 

    db.Test.find({ "$where" : "this.Age==23 || this.Age==50" }).limit(50).sort({ "Age" : -1 }); 
    db.Test.find({ "$where" : "this.Age==23 || this.Age==50" }).limit(50).sort({ "Age" : -1 }).explain(); 

查询字段${Fields}
  • 如下图,查询_id和这些个字段{Name:1,Age:1} 

    db.Test.find({ "$where" : "this.Age==23 || this.Age==50" }, { "Name" : 1, "Age" : 1 }).limit(50).sort({ "Age" : -1 });
    db.Test.find({ "$where" : "this.Age==23 || this.Age==50" }, { "Name" : 1, "Age" : 1 }).limit(50).sort({ "Age" : -1 }).explain();
    • 1
    • 2

    注:当等于1的时候,就是查询_id和和等于1的字段;当如果等于0时,就是查询除了等于0的字段之外的所有字段,如下图:

    db.Test.find({ "$where" : "this.Age==23 || this.Age==50" }, { "Name" : 0, "Age" : 0 }).limit(50).sort({ "Age" : -1 });
    db.Test.find({ "$where" : "this.Age==23 || this.Age==50" }, { "Name" : 0, "Age" : 0 }).limit(50).sort({ "Age" : -1 }).explain();
    • 1
    • 2

skip跳过
  • 当skip>0的时候表示跳过多少行,比如skip=1,表一起有2条数据,那么就只会查询出第二条数据。

Limit分页
  • 表示每次查询多少行,0的时候标识查询所有,>0则查询指定的行数。

修改
  • 右键表,选中update 

    db.Test.update({ "Age" : 24, "$isolated" : "true" },{$set:{Age:27,}});
    db.Test.find({Age:24});
    • 1
    • 2

删除数据
  • 右键表,选中remove,在窗口中输入如下json即可完成删除 

    db.Test.remove({ "Age" : 26 });
    • 1



  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值