清空 Collections 数据

最近更新时间:2025-07-07 16:58:12

我的收藏

接口定义

truncateCollections() 用于清空 Base 类数据库的 Collection 中所有的数据与索引,仅保留 Collection 配置信息,例如索引类型及参数、分片等设置,减少用户的操作成本。
AffectRes truncateCollections(String databaseName, String collectionName)

接口约束

警告:
执行 truncate 操作将会永久删除指定 Collection 下的所有数据。在操作之前,务必谨慎考虑。

使用示例

private static final String DBNAME = "db-test";
private static final String COLL_NAME = "book-vector";
// truncate
AffectRes affectRes = client.truncateCollections(DBNAME, COLL_NAME);
System.out.println("\\tres: " + affectRes);

入参描述

参数名
是否必选
参数含义
配置方法
databaseName
查询的集合所在的数据库名
数据库名可以通过 listDatabase() 查询并复制,其命名要求如下:
只能使用英文字母,数字,下划线_、中划线-,并以英文字母开头。
长度要求:[1,128]。
collectionName
查询的 Collection 名称。
集合名可以通过 listcollections() 查询并复制,其命名要求如下:
只能使用英文字母,数字,下划线_、中划线-,并以英文字母开头。
长度要求:[1,128]。

出参描述

res: AffectRes{affectedCount=1, code=0, msg='operation success'}
参数名
参数含义
affectedCount
影响行数,即为清空数据的集合数量。