如何在 indexedDB 中使用带有 .upperBound 和 .lowerBound 的复合索引

how to use compound indexes with .upperBound and .lowerBound in indexedDb?

本文关键字:upperBound lowerBound 索引 复合 indexedDB      更新时间:2023-09-26

我可以在indexedDb中使用带有.upperBound和.lowerBound的复合索引吗?我已经尝试过,但它似乎不起作用,所以现在我只是使用

//upper bound on the Date, filter for `A`
IDBKeyRange.bound(['A', '9999-12-12'], ['A', new Date()])
//lower bound on the Date, filter for `A`
IDBKeyRange.bound(['A', new Date()], ['A', '0000-01-01'])

这是一个合理的方法吗?还是我错过了什么?

我相信

你可以使用复合键,所以,快速猜测,但它与"文字"是文字和日期对象是日期对象有关吗?

编辑:为了更清楚,我的意思是类型必须对齐。'9999-12-12' 与 new Date() 的类型不同。此外,类型必须与属性的类型相对应。在对象中,"A"必须对应于字符串属性。在对象中,'9999-12-12' 和 new Date() 都必须对应于字符串(或日期)属性。

因此,请查看对象中的属性类型。如果是字符串,请将新日期更改为使用字符串。 如果是日期,请将"9999-12-12"更改为日期对象。