4.非关系型数据库(Nosql)之mongodb:普通索引,唯一索引
一:普通索引
1創建一個新的數據庫
> use toto;
switched to db toto
> show dbs;
admin?(empty)
local?0.078GB
> use toto;
switched to db toto
> db
toto
>?
2創建100萬條數據
> for(var i=1; i <= 1000000; i++){
...db.c3.insert({name:"zhangsan",age:i});
... }
>db.c3.count();
3無索引查找
>db.c3.find({age:500000}).explain();
4位age字段創建一個索引
db.c3.ensureIndex({age:1});
這時候可以看到服務器端有相應的輸出
?
5有索引查找
db.c3.find({age:500000}).explain();
二:唯一索引
1刪除索引:
db.c3.dropIndex({age:1});
2創建唯一索引
db.c3.ensureIndex({age:1},{unique:true});
db.c3.find({age:500000}).explain();
3在某個key上建立了唯一索引之后,這個對應的值必須唯一,添加不進去重復的了。
db.c3.insert({name:”lisi”,age:100});
4 show collections;
5 db.system.indexes.find();
?
總結
以上是生活随笔為你收集整理的4.非关系型数据库(Nosql)之mongodb:普通索引,唯一索引的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国农业银行银行行号查询系统(中国农业银
- 下一篇: 国产汽车质量排名前五(国产汽车质量排名)