zoukankan      html  css  js  c++  java
  • mongodb university week4

    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

  • 相关阅读:
    android获得屏幕高度和宽度
    Android中RelativeLayout各个属性的含义
    Android JNI知识简介
    Android结束进程方法
    android开发中的图片资源问题
    android framework下public.xml中添加资源问题
    I'm back
    test,exec,match,replace方法区别 正则
    fiddler抓包工具 https抓取 ios手机端抓取
    前端优化方案
  • 原文地址:https://www.cnblogs.com/bigbigtree/p/3488110.html
Copyright © 2011-2022 走看看