mongodb 索引

创建
阅读 2816

mongo

mongo 192.168.50.160:27017
use funsapp
db.getCollection("users").find()

创建索引

db.users.ensureIndex({"name":1},{"unique":true})
db.users.ensureIndex({"email":1},{"unique":true, sparse:true})
db.users.ensureIndex({"phone":1},{"unique":true, sparse:true})

查看索引

db.users.getIndexes()

查看索引大小

db.COLLECTION_NAME.totalIndexSize()

删除索引

db.users.dropIndex("INDEX-NAME")

db.users.dropIndex("email_1")
db.users.dropIndex("phone_1")

删除所有索引

db.users.dropIndexes()

本文链接 https://www.yidiankuaile.com/post/mongodb-index

最后更新
留言
0 条留言