如何在 MongoDB 中找到所有唯一索引?
該db.collection.getIndexes()函式不提供有關唯一性的任何資訊。
uj5u.com熱心網友回復:
getIndexes() 應該管用:
db.collection.createIndex({key: 1}, {unique: true})
db.collection.getIndexes()
[
{
"v" : 2,
"key" : { "_id" : 1 },
"name" : "_id_"
},
{
"v" : 2,
"key" : { "key" : 1 },
"name" : "key_1",
"unique" : true
}
]
如果索引不是唯一的,則"unique": true只是丟失。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/396457.html
