• <tfoot id='mEp4t'></tfoot>
    • <bdo id='mEp4t'></bdo><ul id='mEp4t'></ul>

        <small id='mEp4t'></small><noframes id='mEp4t'>

        <legend id='mEp4t'><style id='mEp4t'><dir id='mEp4t'><q id='mEp4t'></q></dir></style></legend>
        <i id='mEp4t'><tr id='mEp4t'><dt id='mEp4t'><q id='mEp4t'><span id='mEp4t'><b id='mEp4t'><form id='mEp4t'><ins id='mEp4t'></ins><ul id='mEp4t'></ul><sub id='mEp4t'></sub></form><legend id='mEp4t'></legend><bdo id='mEp4t'><pre id='mEp4t'><center id='mEp4t'></center></pre></bdo></b><th id='mEp4t'></th></span></q></dt></tr></i><div id='mEp4t'><tfoot id='mEp4t'></tfoot><dl id='mEp4t'><fieldset id='mEp4t'></fieldset></dl></div>

      1. Couchdb 使用键连接两个文档

        时间:2023-09-07
      2. <legend id='y4GZk'><style id='y4GZk'><dir id='y4GZk'><q id='y4GZk'></q></dir></style></legend>

          <small id='y4GZk'></small><noframes id='y4GZk'>

            <tbody id='y4GZk'></tbody>

              • <i id='y4GZk'><tr id='y4GZk'><dt id='y4GZk'><q id='y4GZk'><span id='y4GZk'><b id='y4GZk'><form id='y4GZk'><ins id='y4GZk'></ins><ul id='y4GZk'></ul><sub id='y4GZk'></sub></form><legend id='y4GZk'></legend><bdo id='y4GZk'><pre id='y4GZk'><center id='y4GZk'></center></pre></bdo></b><th id='y4GZk'></th></span></q></dt></tr></i><div id='y4GZk'><tfoot id='y4GZk'></tfoot><dl id='y4GZk'><fieldset id='y4GZk'></fieldset></dl></div>
                <tfoot id='y4GZk'></tfoot>

                  <bdo id='y4GZk'></bdo><ul id='y4GZk'></ul>
                • 本文介绍了Couchdb 使用键连接两个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有两个文档,一个具有树结构,另一个与第一个文档相关.我试图通过 fk 和 pk 加入这两个文档.我无法得到实际结果,它显示所有空值.

                  I have two documents one with tree structure and the other one relation to the first doc. Im trying to join these two doc`s by fk and pk. I couldnt get the actual results and it displays all null values.

                  第一个文档

                  {
                     "name": "one",
                     "root": {
                              "level1" : {
                                         "level2" : {
                                                   "level3" : {
                                                             "itemone": "Randomkey1",
                                                             "itemtwo": "Randomkey2
                                                            }
                                                  }
                                       }
                           },
                     "type": "firstdoc"
                  }
                  

                  第二个文档

                  {
                      "name"  : "two",
                      "mapBy" : "Randomkey1",
                      "type"  : "senconddoc
                  }
                  

                  我编写了一个 map 函数,它列出了给定级别 1 或 2 或 3 的所有键.现在我想使用密钥加入第一个文档和第二个文档.我尝试了两种方法(第一种:我得到所有(Root,Randomkey),(docName,Randomkey1)但它没有做任何加入.我正在寻找类似的结果(根,文档名)

                  I`ve written a map function, which lists all the keys given a level 1 or 2 or 3 . Now I want o join this first doc and second doc using the key. Ive tried two ways (first: Im getting all (Root, Randomkey), (docName, Randomkey1) but it doesnt do any join. Im looking for a result like (Root, docName)

                  有人可以帮忙解决这个问题

                  Could someone assist in fixing this

                  地图

                  function(doc) {
                     if (doc.type === 'firstdoc' || doc.type === 'seconddoc' ) {
                        var rootObj = doc.Root;
                        for (var level1 in rootObj) {
                  
                           var level2Obj = doc.Root[level1];
                  
                           for (var level2 in level2Obj) {
                  
                             var keys = new Array();
                              var level3Obj = level2Obj[level2];
                  
                              for (var i in level3Obj) {
                  
                                  var itemObj = level3Obj[i];
                  
                                  for (var i in itemObj) {
                                      keys.push(itemObj[i]);
                  
                                      emit(doc.name, [itemObj[i], 0]);
                  
                                       var firstDocName = doc.name;
                  
                                      //This is gives null values
                                      if (doc.Type === 'senconddoc' && doc.mapBy === itemObj[i]) {
                  
                                           emit(firstDocName , doc);
                                      }
                                  }
                              }
                  
                  
                  
                          }
                  
                  
                      }
                  }
                  
                  //This just lists keys to me
                  if (doc.type === 'senconddoc') {
                  
                      emit([doc.mapBy, 1] , doc);
                  }
                  }
                  

                  推荐答案

                  要模拟连接,你必须输出一个带有 _id 的文档,_id 需要指向文档的实际 _id.然后你可以利用 include_docs=true 来拉取相关文档.这里的多对多示例:http://danielwertheim.se/couchdb-多对多关系/

                  To simulate joins you have to output a doc with an _id in it, the value of the _id needs to point to an actual _id of a document. Then you can make use of include_docs=true to pull in the related documents. Example with many-to-many here: http://danielwertheim.se/couchdb-many-to-many-relations/

                  如果这不适用,您可以通过首先返回自定义键来进行两步手动连接.然后对所有文档视图进行第二次查询,指定多个键.

                  If this is not applicable, you can make a two step manual join by first returning custom keys. Then make a second query against the all documents view, with multiple keys specified.

                  这篇关于Couchdb 使用键连接两个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MongoDB汇总子文档上的每个键 下一篇:通过reddit排名算法对mongodb进行排序

                  相关文章

                  最新文章

                • <small id='lIKkt'></small><noframes id='lIKkt'>

                  1. <i id='lIKkt'><tr id='lIKkt'><dt id='lIKkt'><q id='lIKkt'><span id='lIKkt'><b id='lIKkt'><form id='lIKkt'><ins id='lIKkt'></ins><ul id='lIKkt'></ul><sub id='lIKkt'></sub></form><legend id='lIKkt'></legend><bdo id='lIKkt'><pre id='lIKkt'><center id='lIKkt'></center></pre></bdo></b><th id='lIKkt'></th></span></q></dt></tr></i><div id='lIKkt'><tfoot id='lIKkt'></tfoot><dl id='lIKkt'><fieldset id='lIKkt'></fieldset></dl></div>
                    <tfoot id='lIKkt'></tfoot>
                      <bdo id='lIKkt'></bdo><ul id='lIKkt'></ul>

                      <legend id='lIKkt'><style id='lIKkt'><dir id='lIKkt'><q id='lIKkt'></q></dir></style></legend>