Couchdb 使用带有use\u索引的\u find查询时出现问题
我正在尝试使用MongoDB,比如CouchDB 2.x中的Couchdb 使用带有use\u索引的\u find查询时出现问题,couchdb,Couchdb,我正在尝试使用MongoDB,比如CouchDB 2.x中的\u find查询: 通过以下内容,我得到一个警告,我应该使用索引 curl -k -X POST "$COUCHDB_HOST/vacation-at-ibm/_find" \ > -H "Content-Type: application/json" \ > -w "\nhttp_code=%{http_code}\n" \ > --data-binary ' > { >
\u find
查询:通过以下内容,我得到一个警告,我应该使用索引
curl -k -X POST "$COUCHDB_HOST/vacation-at-ibm/_find" \
> -H "Content-Type: application/json" \
> -w "\nhttp_code=%{http_code}\n" \
> --data-binary '
> {
> "selector": {
> "ownerId": {"$eq": "1A4061897"}
> }
> }
> '
{"warning":"no matching index found, create an index to optimize query time",
"docs":[
{...}
http_code=200
但是当我添加use\u index
选项时,我得到一个错误,它找不到我的索引:
curl -k -X POST "$COUCHDB_HOST/vacation-at-ibm/_find" \
> -H "Content-Type: application/json" \
> -w "\nhttp_code=%{http_code}\n" \
> --data-binary '
> {
> "use_index": [
> "_design/EventDocument",
> "events-by-ownerId"
> ],
> "selector": {
> "ownerId": {"$eq": "1A4061897"}
> }
> }
> '
{"error":"unknown_error","reason":"Unknown Error: mango_idx :: {no_usable_index,no_index_matching_name}"}
我假设应该指定设计文档键和视图名称。但这只是一个猜测,因为我没有发现任何关于use\u index
选项的有用文档。没有实际尝试使用它的例子。这是我的设计文档:
{
"_id": "_design/EventDocument",
"_rev": "1-115570169dec7d32845c3b7c6e6978fe",
"language": "javascript",
"views": {
"events-by-ownerId": {
"map": "function(doc) { if (doc.docType == 'event' && doc.ownerId) { var firstDate = null; if (doc.date) { firstDate = doc.date; } emit([doc.ownerId, firstDate], doc); }}"
}
}
}
有人知道如何使用这个选项吗?我是否对设计文档和索引使用了错误的值?因此当他们说,“创建索引”时,他们指的是端点
您需要通过此过程创建索引。您可以指定要存储索引的位置,否则,CouchDB将创建一个设计文档并将索引存储在其中。我也被这个功能弄糊涂了。要在
\u find
中使用索引,必须通过\u index
端点创建芒果语言索引。use_index
字段必须等于包含已创建索引的设计文档的名称,并且不需要前导的\u design/
;如果在创建索引时未指定ddoc
,则设计文档的名称将是uuid。如果设计文档某些索引
有多个索引,您可以将其称为“使用索引”:“某些索引/名称”
。如果没有设计文档名称,则不能仅按索引名称引用索引。即使指定了use\u index
,也不会使用索引,除非查询包含索引定义中的所有字段