1. 程式人生 > >mongodb(2) -索引創建

mongodb(2) -索引創建

lsp log find html 對象 uniq code style unique

在shell中查看集合中已經存在的索引,你可以運行:

db.things.getIndexes()

要查看數據庫中所有的索引,可以運行:

db.system.indexes.find()

創建索引
db.things.ensureIndex({j:1});


建選項

ensureIndex函數的第二個參數是攜帶創建選項的文檔/對象。這些選項有:

選項 默認值
background true/false false
dropDups true/false false
unique true/false false
sparse true/false false
v 索引版本。0=早於v2.0版本,1=更小/更快(當前) 1 in v2.0.除非特殊情境,默認使用1

http://blog.csdn.net/xinghebuluo/article/details/7221639

http://www.cnblogs.com/stephen-liu74/archive/2012/08/01/2561557.html

mongodb(2) -索引創建