SequoiaDB 简介
快速入门
安装部署
数据库实例
分布式引擎
SAC 管控中心
SequoiaPerf 性能分析工具
参考手册
常见问题及解答(FAQ)
版本信息
getIndex - 获取指定索引
db.collectionspace.collection.getIndex(<name>)
SdbCollection
该函数用于获取当前集合中指定的索引信息。
name( string,必填 )
指定需要获取的索引名
Note:
索引名不能是空串,含点(.)或者美元符号($),且长度不超过127B。
函数执行成功时,将返回一个 BSONObj 类型的对象。通过该对象获取集合详细信息列表,字段说明可参考 SYSINDEXES 集合。
函数执行失败时,将抛异常并输出错误信息。
getIndex()
函数常见异常如下:
错误码 | 错误名 | 可能发生的原因 | 解决办法 |
---|---|---|---|
-47 | SDB_IXM_NOTEXIST | 索引不存在 | 检查索引是否存在 |
当异常抛出时,可以通过 getLastErrMsg() 获取错误信息或通过 getLastError() 获取错误码。更多错误处理可以参考常见错误处理指南。
v1.10 及以上版本
获取集合 sample.employee 下名为“$id”的索引信息
> db.sample.employee.getIndex("$id") { "_id": { "$oid": "6098e71a820799d22f1f2165" }, "IndexDef": { "name": "$id", "_id": { "$oid": "6098e71a820799d22f1f2164" }, "UniqueID": 4037269258240, "key": { "_id": 1 }, "v": 0, "unique": true, "dropDups": false, "enforced": true, "NotNull": false, "NotArray": true, "Global": false, "Standalone": false }, "IndexFlag": "Normal", "Type": "Positive" }