zoukankan      html  css  js  c++  java
  • mongodb索引(5)

    1创建索引

        1是正序索引,-1是负序索引

        索引会提高查询时间按,降低插入时间

     db.books.ensureIndex({number:1})

    2.创建索引,指定名称

    db.book.ensureIndex({name:-1},{name:"bookname"})

    3.唯一索引

    db.books.ensureIndex({name:1},{unique:true})

    4.剔除重复值

    db.books.ensureIndex({name:1},{unique:true,dropDups:true})

    5.指定索引进行查询

    db.books.find({no:1}).hint({no:1})

    6.查询目前是用了什么查询索引

     db.books.find({no:1}).explain()

    7.产看索引

    db.system.indexes.find()

    8.创建索引会把表锁住,可以让创建索引放在后台进行解决

     db.books.ensureIndex({number:1},{background:true})

    9.删除索引

     db.runCommand({dropIndexes:"books",index:"no_1"})

  • 相关阅读:
    协程
    多进程
    多线程
    模块进阶
    内建函数
    内建属性
    属性property
    私有化
    深拷贝、浅拷贝
    ==、is
  • 原文地址:https://www.cnblogs.com/youlangta/p/7345916.html
Copyright © 2011-2022 走看看