SequoiaDB 简介
快速入门
安装部署
数据库实例
分布式引擎
SAC 管控中心
SequoiaPerf 性能分析工具
参考手册
常见问题及解答(FAQ)
版本信息
setAttributes - 修改集合的属性
db.collectionspace.collection.setAttributes(<options>)
SdbCollection
该函数用于修改集合的属性。
options ( object,必填 )
通过 options 参数可以修改集合属性:
ReplSize ( number ):写操作需同步的副本数,其可选取值如下:
格式:ReplSize: <number>
ConsistencyStrategy( number ):同步一致性策略
该参数用于指定数据同步优先选择的节点,默认值为 3。
取值如下:
格式:ConsistencyStrategy: 3
ShardingKey ( object ):分区键,取值为 1 或 -1,表示正向或逆向排序
格式:ShardingKey: {<字段1>: <1|-1>, [<字段2>: <1|-1>, ...]}
ShardingType ( string ):分区方式,默认为 hash 分区,其可选取值如下:
集合只能存在于一个数据组中。
格式:ShardingType: "hash" | "range"
Partition ( number ):分区数,仅当选择 hash 分区时填写,代表了 hash 分区的个数,其值必须是2的幂,范围在[2^3,2^20]
集合只能存在于一个数据组中。
格式:Partition: <分区数>
AutoSplit ( boolean ):标识新集合是否开启自动切分功能,默认值为 false
格式:AutoSplit: true | false
EnsureShardingIndex ( boolean ):标识是否创建分区索引,默认值为 true
Compressed ( boolean ):标识集合是否开启数据压缩功能
如果设置 Compressed 为 true,而没有指定 CompressionType,则 CompressionType 为 "lzw"。
格式:Compressed: true | false
CompressionType ( string ):集合的压缩算法,"snappy" 或者 "lzw"
格式:CompressionType: "snappy" | "lzw"
StrictDataMode ( boolean ):标识对该集合的操作是否开启严格数据类型模式
格式:StrictDataMode: true | false
AutoIncrement ( object ):自增字段
格式:AutoIncrement: <option>
Note:
- 各个选项的具体使用方式见 createCL()。
- 分区集合不能修改与分区相关的属性,如 ShardingKey、Partition 等。
- EnsureShardingIndex 和 AutoSplit 仅对当前该次操作生效,仅当修改分区属性,如 ShardingKey 等时有效。
AutoIndexId ( Bool ):标识是否创建 $id 索引,默认值是 true
格式:AutoIndexId: true | false
Note:
- 各个选项的具体使用方式见 db.collectionspace.createCL()。
- 分区集合不能修改与分区相关的属性,如 ShardingKey、Partition 等。
- EnsureShardingIndex 和 AutoSplit 仅对当前该次操作生效,仅当修改分区属性,如 ShardingKey 等时有效。
函数执行成功时,无返回值。
函数执行失败时,将抛异常并输出错误信息。
setAttributes()
函数常见异常如下:
错误码 | 错误类型 | 可能发生的原因 | 解决办法 |
---|---|---|---|
-32 | SDB_OPTION_NOT_SUPPORT | 选项暂不支持 | 检查当前集合属性,如果是分区集合不能修改与分区相关的属性 |
当异常抛出时,可以通过 getLastErrMsg() 获取错误信息或通过 getLastError() 获取错误码。更多错误处理可以参考常见错误处理指南。
v2.10 及以上版本
创建一个普通集合,然后将该集合修改为分区集合。
> db.sample.createCL('employee') > db.sample.employee.setAttributes({ShardingKey: {a: 1}, ShardingType: "hash"})
创建一个普通集合,然后将该集合修改为分区集合,并且自动切分:
> db.sample.createCL('employee') > db.sample.employee.setAttributes({ShardingKey: {a: 1}, ShardingType: "hash", AutoSplit: true})
创建一个普通集合,然后将该集合修改为 snappy 压缩
> db.sample.createCL('employee') > db.sample.employee.setAttributes({CompressionType: 'snappy'})
创建一个有自增字段的集合,修改其自增起始值
> db.sample.createCL('employee', {AutoIncrement: {Field: "studentID"}}) > db.sample.employee.setAttributes({AutoIncrement: {Field: "studentID", StartValue: 2017140000}})