滥用pouchDB的doc ID:获取第一个前缀元素
Abuse pouchDB's doc ID: Get first prefix element
以下是一些示例 ID:
someText_1
someText_2
someText_3
someOtherText_1
someOtherText_2
我想得到下划线后数值最大的"someText"-元素:someText_3
allDocs({startkey: 'someText_', endkey: 'someText_\uffff'});
将生成所有 "someText_" 元素。
有没有办法只接收 "someText_3"?我想避免 map/reduce 查询,因为保证的本地存储 space 非常有限。
我已经阅读:
http://pouchdb.com/2014/05/01/secondary-indexes-have-landed-in-pouchdb.html(不用时map/reduce)
Pouchdb document id complex key(有同样的问题)
很遗憾,您无法搜索 "inside" 带有 P/CouchDB _id 的字符串 - 您只能进行前缀搜索。当然,前缀搜索并不能解决您的整数问题,因为就字符串而言,1 < 10 < 2
.
一种选择是直接使用 pouchdb-collate。因此,例如,您的 ID 可以从 [2, 'someText']
这样的对象生成。这使您可以轻松地搜索高于和低于特定值的整数,但缺点是很难搜索 'someText'
.
另一种选择是硬着头皮使用 map/reduce 或 pouchdb-find。如果您的查询需求足够复杂,您可能不得不这样做。
以下是一些示例 ID:
someText_1
someText_2
someText_3
someOtherText_1
someOtherText_2
我想得到下划线后数值最大的"someText"-元素:someText_3
allDocs({startkey: 'someText_', endkey: 'someText_\uffff'});
将生成所有 "someText_" 元素。 有没有办法只接收 "someText_3"?我想避免 map/reduce 查询,因为保证的本地存储 space 非常有限。
我已经阅读:
http://pouchdb.com/2014/05/01/secondary-indexes-have-landed-in-pouchdb.html(不用时map/reduce)
Pouchdb document id complex key(有同样的问题)
很遗憾,您无法搜索 "inside" 带有 P/CouchDB _id 的字符串 - 您只能进行前缀搜索。当然,前缀搜索并不能解决您的整数问题,因为就字符串而言,1 < 10 < 2
.
一种选择是直接使用 pouchdb-collate。因此,例如,您的 ID 可以从 [2, 'someText']
这样的对象生成。这使您可以轻松地搜索高于和低于特定值的整数,但缺点是很难搜索 'someText'
.
另一种选择是硬着头皮使用 map/reduce 或 pouchdb-find。如果您的查询需求足够复杂,您可能不得不这样做。