跳到主要内容

cleanupExpired()

function cleanupExpired(
vm,
namespace,
entityName,
options?): Promise<CleanupExpiredResult>;

Defined in: packages/rxdb/src/version/cleanup-expired.ts:71

清理不再满足过滤条件的本地过期数据

注意: 删除操作不会记录到 RxDBChange,因此不会同步到远程 这适用于"只保留最近 N 天数据"的场景

Parameters

ParameterTypeDescription
vmVersionManagerVersionManager 实例
namespacestring命名空间
entityNamestring实体名
options?CleanupExpiredOptions清理选项

Returns

Promise<CleanupExpiredResult>

清理结果

Example

const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
const { removed } = await cleanupExpired(vm, 'public', 'Order', {
filter: {
combinator: 'and',
rules: [{ field: 'updatedAt', operator: '>=', value: thirtyDaysAgo }]
}
});
console.log(`Removed ${removed} expired records`);