M102: MongoDB for DBAs chapter 3 performance学习记录

本文记录了M102 MongoDB for DBAs第三章关于性能的学习,包括在Windows环境下搭建MongoDB 3.4,完成课后习题,涉及索引创建、性能监控和故障排查等,探讨了WiredTiger存储引擎相对于MMAPv1的特性优势。
摘要由CSDN通过智能技术生成

M102: MongoDB for DBAs chapter 3 performance学习记录

运行环境

操作系统:windows 10 家庭中文版
Mongodb :Mongodb 3.4

Mongodb安装路径:E:>MongoDB\Server\3.4\bin\
Mongodb存储路径:E:>MongoDB\data

课后习题

3.1题目

Download Handouts:

performance__m102_performance_reorg_537a56c08bb48b7c467a20d3.zip

Start a mongod server instance (if you still have a replica set, that would work too).

Next, download the handout and run:

mongo --shell localhost/performance performance.js

homework.init()

Build an index on the “active” and “tstamp” fields. You can verify that you’ve done your job with

db.sensor_readings.getIndexes()

When you are done, run:

homework.a()

and enter the numeric result below (no spaces).

Note: if you would like to try different indexes, you can use db.sensor_readings.dropIndexes() to drop your old index before creating a new one. (For this problem you will only need one index beyond the _id index which is present by default.)

解答

下载指定的performance__m102_performance_reorg_537a56c08bb48b7c467a20d3.zip文件,解压后放在E:\MongoDB目录下,启动我的mongod服务:

C:\Users\Shinelon>e:
E:\>MongoDB\Server\3.4\bin\mongod.exe --dbpath MongoDB\data

按要求通过js脚本启动mongo数据库

E:\>MongoDB\Server\3.4\bin\mongo.exe --shell localhost/performance MongoDB\performance.js
MongoDB shell version v3.4.6
connecting to: mongodb://localhost/performance
MongoDB server version: 3.4.6
type "help" for help
Server has startup warnings:
2018-04-08T20:18:31.157-0700 I CONTROL  [initandlisten]
2018-04-08T20:18:31.157-0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-04-08T20:18:31.157-0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-04-08T20:18:31.158-0700 I CONTROL  [initandlisten]
>

初始化homework脚本:

> homework.init()
{
        "connectionId" : 2,
        "n" : 0,
        "syncMillis" : 0,
        "writtenTo" : null,
        "err" : null,
        "ok" : 1
}
still working...
{
        "connectionId" : 2,
        "updatedExisting" : true,
        "n" : 20000,
        "syncMillis" : 0,
        "writtenTo" : null,
        "err" : null,
        "ok" : 1
}
count: 20000

先查看sensor_readings集合中索引情况:

> db.sensor_readings.getIndexes()
[
        {
                "v" : 2,
                "key" : {
                        "_id" : 1
                },
                "name" : "_id_",
                "ns" : "performance.sensor_readings"
        }
]

结果显示只在_id字段上有一个默认的索引,下面按题目要求在”active” 和”tstamp”字段创建一个复合索引:

> db.sensor_readings.ensureIndex({
  "active" : 1 , "tstamp" : 1})
{
        "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值