清空 Collections 数据

最近更新时间:2024-09-29 15:47:41

我的收藏

接口定义

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

接口约束

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

使用示例

// link database
Database db = client.database("db-test");
// truncate
AffectRes affectRes = db.truncateCollections("book-vector");
System.out.println("\\tres: " + affectRes);

入参描述

参数名
是否必选
参数含义
配置方法
collectionName
所需删除的 Collection 名称。
Collection 命名要求如下:
只能使用英文字母,数字,下划线_、中划线-,并以英文字母开头。
长度要求:[1,128]。

出参描述

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