简体   繁体   English

从 couchdb 检索数据(如何验证值是否在数据库中)

[英]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.

相关问题 如何从 Python 中检索 CouchDB 复制状态 - How to retrieve CouchDB replication status from Python 如何使用自动完成(Django)从数据库中检索数据 - How to retrieve data from database with autocomplete (Django) 如何从couchdb检索所有文档并使用python将其转换为CSV - How to retrieve all docs from couchdb and convert it as CSV using python 使用Javascript Django从数据库中的值检索数据 - Retrieve data from value in database using Javascript Django 如何使用django从mongodb数据库中检索数据? - how to retrieve data from mongodb database using django? 如何从 Django 中的 MySQL 数据库中检索数据并将其显示在 html 页面中? - How to retrieve data from MySQL database in Django and display it in html page? 我应该如何在SQL数据库中插入和检索数据列表? - How should I insert & retrieve lists of data to & from an SQL database? 如何在Django的某个条目中从数据库中检索所有数据块? - How to retrieve all data blocks from database at a certain entry in Django? 如何在Python中从格式不规则的文本数据库中检索数据? - How to retrieve data from an irregularly formatted text database in Python? 如何使用 URL 从数据库中检索数据 - How can I retrieve Data from a database by using the URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM