zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

[MongoDB] Mongo 表字段添加索引, 查看索引, 删除索引

MongoDB索引 查看 删除 添加 表字 mongo
2023-09-14 09:02:26 时间

通过llama.cpp与羊驼聊天的网页界面- 详解 Serge 的启动使用

 

查看索引:

db.getCollection('xx').getIndexes();

 

创建索引:

# 1 代表升序,-1代表降序,name 指定索引名

db.getCollection('xx').createIndex( {"title": 1}, {"name":"idx_xxx"} );

 

创建复合索引:

db.getCollection('xx').createIndex( {"title": 1, "created_at": -1} );

 

内嵌字段创建索引:

db.集合名.createIndex( {"字段名.内嵌字段名":1}, {"name":'idx_字段名_内嵌字段名'} )

 

删除索引:

db.getCollection('xx').dropIndex("idx_xxx");

 

Ref:https://www.runoob.com/mongodb/mongodb-indexing.html

https://www.cnblogs.com/xuliuzai/p/9965229.html

Link:https://www.cnblogs.com/farwish/p/14817554.html