[英]Retrieve data from couchdb (how to verify that a value is in a database)
how can I retrieve data from a couchdb database, not in a document of a database but in all the documents of the database.如何从 couchdb 数据库中检索数据,而不是在数据库的文档中,而是在数据库的所有文档中。 I already verified if a value was in a document but I want now to verify if a value is in a special database.
我已经验证了一个值是否在文档中,但我现在想验证一个值是否在一个特殊的数据库中。
It's hard to be specific here, since you're not providing any example data.在这里很难具体说明,因为您没有提供任何示例数据。 Do you mean if a particular value exists anywhere in any document, or if a specific field holds a specific value in any document?
您的意思是某个特定值是否存在于任何文档中的任何位置,或者某个特定字段是否在任何文档中包含特定值?
If you mean the former, I'd advice you to come up with a better data model.如果您指的是前者,我建议您提出更好的数据 model。 So let's focus on the latter.
所以让我们关注后者。 Let's say your documents contain the field called
special
, and you want to know if any such documents has the value 99 in this field:假设您的文档包含名为
special
的字段,并且您想知道是否有任何此类文档在此字段中具有值 99:
{
...
"special": 99
}
Create a view keyed on the value:创建一个以值为键的视图:
function(doc) {
if (doc && doc.special) {
emit(doc.special, null);
}
}
Now you can check if documents exist in this database for values of the special field:现在您可以检查此数据库中是否存在文档以获取特殊字段的值:
# Look for the value 99
% acurl 'https://XYZ.cloudant.com/aaa/_design/test/_view/special?key=99'
{"total_rows":3,"offset":2,"rows":[
{"id":"a3c424e99f3cc9988a2553bb680ac7f8","key":99,"value":null}
]}
In my databse aaa
there is one document, with the id a3c424e9...
that has the value 99 in the special
field.在我的数据库
aaa
中有一个文档,其 id a3c424e9...
,在special
字段中的值为 99。 This is a so-called reverse index.这就是所谓的反向索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.