delete - 删除数据
delete() 用于从 collection 中删除记录。您可以按ID、元数据筛选器或文档筛选器删除。
信息
仅支持在使用 Client 连接时,才能使用该接口。关于 Client 的详细介绍,参见 Client。
前提条件
-
您已经安装了 pyseekdb,有关安装 pyseekdb 的详细信息,参见 快速开始。
-
您已经连接到数据库。有关连接的详细操作参见 Client。
-
如果您使用的是客户端模式的 seekdb 或者 OceanBase 数据库,请确保连接的用户已拥有待操作的表的
DELETE权限,查看当前用户权限的相关操作 请参见 查看用户权限。如果不具备该权限,请联系管理员为您授权,用户授权的相关操作请参见 直接授予权限。
请求参数
delete(
ids=ids,
where=where,
where_document=where_document
)
| 参数 | 取值类型 | 是否必选 | 描述 | 取值示例 |
|---|---|---|---|---|
ids | string 或者 List[str] | 可选 | 需要删除的 ID。可以是单个,也可以是数组。 | item1 |
where | dict | 可选 | Metadata 筛选条件。 | {"category": {"$eq": "AI"}} |
where_document | dict | 可选 | Document 筛选条件。 | {"$contains": "obsolete"} |
信息
id、where 或 where_document 中必须至少有一个。
请求示例
import pyseekdb
# Create a client
client = pyseekdb.Client()
collection = client.get_collection("my_collection")
# Delete by IDs
collection.delete(ids=["item1", "item2", "item3"])
# Delete by single ID
collection.delete(ids="item1")
# Delete by metadata filter
collection.delete(where={"category": {"$eq": "AI"}})
# Delete by comparison operator
collection.delete(where={"score": {"$lt": 50}})
# Delete by document filter
collection.delete(where_document={"$contains": "obsolete"})
# Delete with combined filters
collection.delete(
where={"category": {"$eq": "AI"}},
where_document={"$contains": "deprecated"}
)
返回参数
无