duplicate key error index: student.LABELNE
T.$name_1 dup key: { : \"yuan\" }",
"code" : 11000,
"ok" : 0
}
>
?
11.2 添加其他索引
?
> db.LABELNET.ensureIndex({"name":1,"age":1});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
>
?
11.3 查看所有索引
?
> db.LABELNET.getIndexes();
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "student.LABELNET"
},
{
"v" : 1,
"key" : {
"name" : 1,
"age" : 1
},
"name" : "name_1_age_1",
"ns" : "student.LABELNET"
}
]
?
11.4 删除索引
可能随着业务需求的变化,原先建立的索引可能没有存在的必要了,可能有的人想说没必要就没必要呗, 但是请记住,索引会降低CUD这三种操作的性能。
?
> db.LABELNET.dropIndex("name_1_age_1");
{ "nIndexesWas" : 2, "ok" : 1 }
> db.LABELNET.getIndexes();
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "student.LABELNET"
}
]
>
基本命令 就学到这里了,下篇将学习使用 mongodb 的 C#驱动 实现增删改查!
?