2017-12-05 38 views
0

매우 큰 문서의 경우 CouchDB 2.1에서보기를 만들려고합니다 (각 문서에 대해 약 300k-900k 줄, 총 약 15-20 개의 문서).문자열로 키가 큰 문서의 Couchdb보기가 만료됩니다.

서류는 다음과 같다 :

{ 
"222123456": { 
    "_id": "222123456", 
    "type": "Order", 
    "0300": { 
     "51234567": { 
      "_id": "51234567", 
      "type": "Material", 
      "DS": "M532F1234567", 
      "HTZ": "M532-F1234-000-00", 
      "A name for some material": { 
       "_id": "A name for some material", 
       "type": "Description", 
       "0054": { 
        "600": { 
         "1": { 
          "_id": "1", 
          "type": "Amount", 
          "X": { 
           "11220": { 
            "_id": "11220", 
            "type": "row" 
           }, 
           "_id": "X", 
           "type": "Bulk" 
          } 
         }, 
         "_id": "600", 
         "type": "Site" 
        }, 
        "_id": "0054", 
        "type": "Pos" 
       } 
      } 
     }, 
     "51255111": { 
      // And another material 
      // ... 
     }, 
     "_id": "0300", 
     "type": "Process" 
    } 
    // + more orders with more items 
}, 
"222555666": { 
    // Another order with more processes which contain even more materials 
    // ... 
}, 
"_id": "FileImport_001", 
"_rev": "1-2f77e699332bb7c76a137b86f83bbe91", 
"type": "Machine" 
} 

모든 문서는 1-N 주문을 가지고, 모든 주문은 1-n 개의 프로세스를 가지고 있으며, 모든 프로세스가 내가 쿼리하기 위해 노력하고있어 1-n 개의 자료가 포함되어 있습니다. 현재 뷰는 for 루프를 사용하여 모든 주문, 프로세스 및 자료를 반복합니다.

function (doc) { 
    var splitMsn = doc._id.split("_"); // Split _id into [FileImport, 001] array 
    for (var key_order in doc) { // For every order in the document... 
     if (typeof doc[key_order] == 'object' && doc[key_order] != '') { // where the value is an object and not empty... 
      var order = doc[key_order]; // Save the order as a value 
      for (var key_process in order) { // ...and search all processes in that order nr 
       if (typeof order[key_process] == 'object' && order[key_process] != '') { // If process contains an object as value and it's not empty 
        var process = order[key_process]; // Save the process as a value 
        for (var key_matnr in process) { // For every material in the process 
         if (typeof process[key_matnr] == 'object' && process[key_matnr] != '') { // If material nr contains an object as value and not empty 
          var matnr = process[key_matnr]; // Save material nr as value 
          for (var key_matname in matnr) { // For every material name in the material number 
           if (typeof matnr[key_matname] == 'object' && matnr[key_matname] != '') { // Contains object and not empty 
            var matname = matnr[key_matname]; // Save material name 
            emit([splitMsn[1], key_order, key_process, key_matnr], matname); // emit [001, 222123456, 0300, 51234567], Material name 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
} 

내가 특정 문서 번호, 순서, 공정 및 자재 번호를 조회 할 수 있습니다이보기로 :

내가 사용하고 전망이다. 그 대가로 금액 (예 : 1)을 재료 이름으로받습니다.

하나의 문서를 사용할 때 인덱스는 잘 생성되지만 두 번째 문서 (15 개 또는 20 개는 제외)로도보기를 만드는 동안 "OS process timed out"이라고 표시됩니다.

내 질문 :이 모든 단계를 반복하여 내가 필요로하는 깊이 묻힌 "금액"값을 얻는 더 빠르고 우아한 방법이 있습니까?

미리 감사드립니다.

답변

1

시스템이 자체로부터 보호하고 있습니다.

일반적으로 대용량 문서를 사용하면 CouchDB의 단 맛집이 나오지 않습니다. 깊게 중첩 된 구조와 매우 복잡한지도를 추가하면 상황이 더욱 악화됩니다.

데이터 모델을 재고하는 것이 좋습니다. (훨씬) 작은 문서를 사용하십시오 (한 자료에 하나, 말하십시오). 맵 기능도 훨씬 간단합니다.

+0

답변 해 주셔서 감사합니다. 주문마다 하나의 문서를 사용하도록 데이터 모델을 변경 했으므로 첫 번째 색인은 오래 걸리지 만 색인을 업데이트하는 것이 훨씬 빨라졌습니다. –