简体   繁体   English

Couchdb从文档中的两个数组中发出文档

[英]Couchdb emit document from two arrays in document

I have several documents in my couchdb database. 我的ouchdb数据库中有几个文档。 Followng is an example of it: Followng就是一个例子:

    "company": [
           "xyz",
           "abcintl"
       ],
    "usermentions": [
           "Abce",
           "Swat",
           "axis"
       ],

I have a company name as my keyword. 我有一个公司名称作为关键字。 Let's say 'abcintl'. 假设为“ abcintl”。 I want to emit a document who has 'abcintl' in company OR usermentions. 我想发出公司或用户名中带有“ abcintl”的文档。 If any of these attributes contain my keyword I want to emit that document. 如果这些属性中的任何一个包含我的关键字,我都希望发出该文档。

Thanks, 谢谢,

If you want to find the documents that contain a certain keyword, just emit the company and usermentions array values. 如果要查找包含某个关键字的文档,只需发出companyusermentions数组值。

function (doc) {
  doc.company.forEach(function (company) {
    emit(company);
  });

  doc.usermentions.forEach(function (mention) {
    emit(mention);
  });
}

Your view will include all the company/usermentions for each document. 您的视图将包括每个文档的所有公司/部分。 So you can query your view with key="abcintl" , and you'll find all the document IDs that contain that value in either array. 因此,您可以使用key="abcintl"查询您的视图,并且在任一数组中都将找到包含该值的所有文档ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM