1、index Creation,background

如果在foreground运行index,会阻塞其他writer,如果background运行,会比较慢,但不会阻塞其他writer,可以并发写入。

但是在产品级别的应用中,你可以同时建立replica set,在其中一个set中运行EnsureIndex foreground ,在其他的set中允许访问,然后再同步。

Tips:

  A mongod instance can only build one background index at a time per database.

  Although the database server will continue to take requests, a background index creation still blocks the mongo shell that you are using to create the index.

  Creating an index in the background takes longer than creating it in the foreground

2、 解释Index背后 mongodb的操作

db.foo.find({c:1}).explain()

该函数返回find对应于背后的数据库操作。

3、当同时有几种index可以使用时,mongodb会同时运行,当有一个index查找到结果时,会都停止。

4、db.collections.totalIndexSize() 返回index的大小bytes

5、对index的选择,进行筛选

6、hint指定选用哪个index,

优先选用c index

db.foo.find({a:100,b:100}).hint({c:1})

.sort()或者.hint()中选用的index,如果为sparse稀疏Index,则会略去该index中值为null的记录;如果使用hint({$natural:1}),则会使用BasicCusor,遍历所有文件。

foo.find(query).sort().hint([])

7、geospatial index

ensureIndex({location:'2D',type:1})

find({location:{$near:[50,50]}})

地理坐标查询:

存储顺序:longitude,latitude

db.runCommand({geoNear:'stores',near:[50,50] ,spherical : true, maxDistance:1})

spherical标示曲面坐标为真,maxDistance标示One radian指最大长度为地球半径,约1/6个地球周长,即六分之一的数据。

mongodb优化

loggine slow queries

当查询时间很长时,该次查询会被记录在log文件中。

profiler有三个层次:0,1,2;

0为不记录;1为记录时间长的查询;2为记录所有查询,多用在dubug程序

在启动mongod时:mongod --dbpath... --profile 1 --slowms 2

db.system.profile.find({millis:{$gt:1000}}).sort({ts:-1})

Mongotop:

Sharding Key

mongodb university week4的更多相关文章

  1. MongoDB with D3.js

    MongoDB with D3.js I consider interactive data visualization to be the critical tool for exploration ...

  2. MongoDB统计文档(Document)的数组(Array)中的各个元素出现的次数

    一,问题描述 [使用 unwind 操作符 “解包” Document 里面的Array中的每个元素,然后使用 group 分组统计,最后使用 sort 对分组结果排序] 从 images.json ...

  3. Mongodb aggregation 基本操作示例

    MongoDB二个主要的操作:一个是查询,另一个是统计.对于查询而言,主要是find()方法,再配合Filters组合多个查询条件. 对于统计而言,则主要是aggregate操作,比如 group.s ...

  4. MongoDB 更新数组中的元素

    本文记录如何更新MongoDB Collection 中的Array 中的元素.假设Collection中一条记录格式如下: 现要删除scores 数组中,"type" 为 &qu ...

  5. MongoDB资料大全

    摘要: 为了帮助大家进一步了解MongoDB,云栖社区组织翻译了GitHub Awesome MongoDB 资源,涵盖MongoDB中常见的库与工具.应用列表.以及相关的文档.教程等资源. Mong ...

  6. 简明 MongoDB 入门教程

    MongoDB 是免费开源的跨平台 NoSQL 数据库,命名源于英文单词 humongous,意思是「巨大无比」,可见开发组对 MongoDB 的定位.与关系型数据库不同,MongoDB 的数据以类似 ...

  7. Getting Started with MongoDB (MongoDB Shell Edition)

    https://docs.mongodb.com/getting-started/shell/ Overview Welcome to the Getting Started with MongoDB ...

  8. MongoDB 红宝书-MongoDB官网使用指南

    本文转载自Mongodb中文社区:http://www.mongoing.com/archives/27359 无论你是MongoDB的使用者.爱好者.初学者还是路人甲,有一个学习与进修的资源宝藏是千 ...

  9. 提高生产性工具(五) - 数据的过滤器和图形化(适用于 MVC5 + MongoDB)

    在下面流水账似的文章之前,先将一些感悟说一下. 1.如果一个系统对于某个功能在至少三个地方使用的话,必须将其抽象提炼出来,而且时间点最好是大规模测试之前. 2.提炼出来的功能,如果品质做得好,整个系统 ...

随机推荐

  1. jQuery 基础(4)jQuery 尺寸

    jQuery 尺寸方法jQuery 提供多个处理尺寸的重要方法:width()height()innerWidth()innerHeight()outerWidth()outerHeight()jQu ...

  2. centos 搭建git服务器

    centos 6搭建git服务器 安装 rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm yum ins ...

  3. angular评论星级指令

    地址: https://github.com/happen-zh/myStar 支持最大数,是否必填,回调,是否只读

  4. JS-鼠标经过显示二级菜单

    在css处添加了border样式为了看得更清楚——源代码有一个程序漏洞,存在一个很烦人的大bug. <ul class="nav"> <li class=&quo ...

  5. sql附加数据库错误5120

    http://zhidao.baidu.com/link?url=p1o8EjUhn-RYFt1D4uIM-5HQF1oXZIRlPGaDiZ2FRMDzZDG1ooSARfkoPWG6SzTJTN6 ...

  6. UI学习之常用方法

    1.-(BOOL) respondsToSelector: selector 用来判断是否有以某个名字命名的方法(被封装在一个selector的对象里传递) if ([delegate respond ...

  7. git命令拾遗

    要随时掌握工作区的状态,使用git status命令. 如果git status告诉你有文件被修改过,用git diff可以查看修改内容. HEAD指向的版本就是当前版本,因此,Git允许我们在版本的 ...

  8. securecrt中文乱码

    1.直接打开Linux的terminal中文字符显示正常,但是用securecrt登陆后中文显示不正常 解决方法:securecrt字符集设置不对 路径:Options -> Session O ...

  9. Centos 7.0查看硬盘使用情况 命令

    查看硬盘使用情况 df -hl [root@localhost ~]# df -hl文件系统         容量    已用    可用    已用%.     挂载点/dev/sda3       ...

  10. Lua弱引用table

    弱引用table 与python等脚本语言类似地,Lua也采用了自动内存管理(Garbage Collection),一个程序只需创建对象,而无需删除对象.通过使用垃圾收集机制,Lua会自动删除过期对 ...