我有以下查询:
{
"selector":{
"lastname":{
"$regex":"(?i)[cç][oòóôõöø]"
},
"firstname":{
"$gt":null
},
"type":"person",
"owner":{
"$in":["admin"]
}
},"sort":["lastname","firstname"]
}
尝试了很多指数:
{
"type": "json",
"def": {
"fields": [
{
"lastname": "asc"
}
]
}
}
{
"type": "json",
"def": {
"fields": [
{
"lastname": "asc"
},
{
"firstname": "asc"
}
]
}
}
{
"type": "json",
"def": {
"fields": [
{
"lastname": "asc"
},
{
"firstname": "asc"
},
{
"type": "asc"
},
{
"owner": "asc"
}
]
}
}
但都没有效果。仅供我使用CouchDB 2.1.0。
我还尝试将"sort":["lastname","firstname","type","owner"]
添加到查询中。仍然收到警告:no matching index found, create an index to optimize query time
我做错了什么?
编辑:我将PouchDB直接用于我的CouchDB服务器(没有同步),如果这可以帮助......
答案 0 :(得分:0)
您之前是否创建了索引?
this._DB.createIndex({
index: { fields: ['lastname', 'firstname'] },
ddoc: "my-index-design-doc"
})
在你的.find中使用它而不是在
use_index: 'my-index-design-doc'
?
答案 1 :(得分:0)
请注意,在大型数据库中,查询所带来的性能后果将非常严重。运算符$ in和$ regex将处理内存中的整个数据库,因为它不使用任何索引-至少在最新的CouchDB版本:3.0.2。中也不能使用。
另一方面,$ eq,$ gt-$ gte,$ lt-$ lte将索引而不处理所有数据。这就是它变得聪明的地方。