我的CouchDB Design Dokument中的列表函数中的“compilation_error”

时间:2016-02-15 17:14:27

标签: javascript couchdb

我在Windows 10 64bit下使用Apache主页的CouchDB 1.6.1安装程序。

目前我使用两个设计文档为我做了一些事情。

第一个是

http://127.0.0.1:5984/patients/_design/patients/_list/list-patients/by_ward

{
   "_id": "_design/patients",
   "_rev": "63-fae9e98ab23e0f6fc850f2895de443cc",
   "language": "javascript",
   "views": {
       "by_ward": {
           "map": "function(doc) {if (doc._id) {emit([doc.Ward,doc.Lastname],doc);}}"
       }
   },
   "lists": {
       "list-patients": "function (head, req) {provides('json', function() {var results = []; while (row = getRow()) {results.push({_id: row.value._id, _rev: row.value._rev, Firstname: row.value.Firstname, Lastname: row.value.Lastname, KV: row.value.KV, lengthofstay: row.value.lengthofstay, Birthday: row.value.Birthday, Age: row.value.Age, Discipline1: row.value.Discipline1, EPA1: row.value.EPA1, Gender1: row.value.Gender1, Ward: row.value.Ward, RoomNumber1: row.value.RoomNumber1, Bed: row.value.Bed, ContactBitmapL1: row.value.ContactBitmapL1, PatientName1: row.value.PatientName1, CareLevel: row.value.CareLevel, mark_1: row.value.mark_1, mark_2: row.value.mark_2, mark_3: row.value.mark_3, mark_4: row.value.mark_4, mark_5: row.value.mark_5, mark_6: row.value.mark_6, mark_7: row.value.mark_7, mark_8: row.value.mark_8, mark_9: row.value.mark_9, mark_10: row.value.mark_10 }); } send(JSON.stringify(results)); }); }"
   }
}

列表功能具有更好的可读性:

function (head, req) {

    provides('json', function() {

        var results = []; 

        while (row = getRow()) {

            results.push({

                _id: row.value._id,
                _rev: row.value._rev,
                Firstname: row.value.Firstname,
                Lastname: row.value.Lastname,
                KV: row.value.KV,
                lengthofstay: row.value.lengthofstay,
                Birthday: row.value.Birthday,
                Age: row.value.Age,
                Discipline1: row.value.Discipline1,
                EPA1: row.value.EPA1,
                Gender1: row.value.Gender1,
                Ward: row.value.Ward,
                RoomNumber1: row.value.RoomNumber1,
                Bed: row.value.Bed,
                ContactBitmapL1: row.value.ContactBitmapL1,
                PatientName1: row.value.PatientName1,
                CareLevel: row.value.CareLevel,
                mark_1: row.value.mark_1,
                mark_2: row.value.mark_2,
                mark_3: row.value.mark_3,
                mark_4: row.value.mark_4,
                mark_5: row.value.mark_5,
                mark_6: row.value.mark_6,
                mark_7: row.value.mark_7,
                mark_8: row.value.mark_8,
                mark_9: row.value.mark_9,
                mark_10: row.value.mark_10

            });

        }

        send(JSON.stringify(results));

    });

}

并且像魅力一样工作,并给我我想要的输出。(没有发现时没空,没有错误,正确的列表,如果找到文件)

现在我尝试将类似的设计用于另一种设计

http://127.0.0.1:5984/admissions/_design/admissions/_list/list-admissions/by_patient

{
   "_id": "_design/admissions",
   "_rev": "26-f17c4579ba9c32c2fa577aa8346ceb54",
   "language": "javascript",
   "views": {
       "by_patient": {
           "map": "function(doc) {if (doc._id) {emit([doc.Patient,doc.SortNr],doc);}}"
       }
   },
   "lists": {
       "list-admissions": "function (head, req) {provides('json', function() {var results = []; while (row = getRow()) {results.push({_id: row.value._id, _rev: row.value._rev, SomeType: row.value.SomeType, taken_Date: row.value.taken_Date, taken_Time: row.value.taken_Time, Patient: row.value.Patient, Nurse: row.value.Nurse, SortNr: row.value.SortNr, 00_02: row.value.00_02, 00_03: row.value.00_03, 00_03_99: row.value.00_03_99, 00_04: row.value.00_04, 00_05: row.value.00_05, 00_06: row.value.00_06, 00_08: row.value.00_08, 00_10: row.value.00_10, 00_10_99: row.value.00_10_99, 00_14: row.value.00_14, 00_15: row.value.00_15, 00_16: row.value.00_16, 00_17: row.value.00_17, 00_18: row.value.00_18, 00_19: row.value.00_19, 00_20: row.value.00_20, 99_01: row.value.99_01, 99_02: row.value.99_02, 99_03: row.value.99_03, 99_04: row.value.99_04, 99_05: row.value.99_05, 99_06: row.value.99_06, 99_07: row.value.99_07, 99_08: row.value.99_08, 99_09: row.value.99_09, 99_10: row.value.99_10, 99_11: row.value.99_11, 99_12: row.value.99_12, 99_13: row.value.99_13, 99_14: row.value.99_14, 99_15: row.value.99_15, 99_16: row.value.99_16, 99_17: row.value.99_17, 99_18: row.value.99_18, 99_19: row.value.99_19, 99_20: row.value.99_20, 99_21: row.value.99_21, 99_22: row.value.99_22, 99_23: row.value.99_23, 99_24: row.value.99_24, 99_24_99: row.value.99_24_99, 99_25: row.value.99_25, 99_25_99: row.value.99_25_99, 99_26: row.value.99_26, 99_26_99: row.value.99_26_99, 99_27: row.value.99_27, 99_27_99: row.value.99_27_99, 99_28: row.value.99_28, 99_28_99: row.value.99_28_99, 99_29: row.value.99_29, 99_29_99: row.value.99_29_99, 99_30: row.value.99_30, 99_30_99: row.value.99_30_99, 99_31: row.value.99_31, 99_31_99: row.value.99_31_99, 99_32: row.value.99_32, 99_33: row.value.99_33, 99_34: row.value.99_34, 99_34_99: row.value.99_34_99, 99_35: row.value.99_35, 99_36_99: row.value.99_36_99, 00_90_01_01: row.value.00_90_01_01, 00_90_01_01_99: row.value.00_90_01_01_99, 00_90_01_02: row.value.00_90_01_02, 00_90_01_03: row.value.00_90_01_03, 00_90_01_04: row.value.00_90_01_04, 00_90_01_05: row.value.00_90_01_05, 00_90_01_08: row.value.00_90_01_08, 00_90_01_09: row.value.00_90_01_09, 00_90_01_10: row.value.00_90_01_10, 00_90_01_12: row.value.00_90_01_12, 00_90_01_15: row.value.00_90_01_15 }); } send(JSON.stringify(results)); }); }"
   }
}

更好的可读性功能:

function (head, req) {

    provides('json', function() {

        var results = [];

        while (row = getRow()) {

            results.push({

                _id: row.value._id,
                _rev: row.value._rev,
                SomeType: row.value.SomeType,
                SomeDate: row.value.SomeDate,
                SomeTime: row.value.SomeTime,
                Patient: row.value.Patient,
                Nurse: row.value.Nurse,
                SortNr: row.value.SortNr,
                00_02: row.value.00_02,
                00_03: row.value.00_03,
                00_03_99: row.value.00_03_99,
                00_04: row.value.00_04,
                00_05: row.value.00_05,
                00_06: row.value.00_06,
                00_08: row.value.00_08,
                00_10: row.value.00_10,
                00_10_99: row.value.00_10_99,
                00_14: row.value.00_14,
                00_15: row.value.00_15,
                00_16: row.value.00_16,
                00_17: row.value.00_17,
                00_18: row.value.00_18,
                00_19: row.value.00_19,
                00_20: row.value.00_20,
                99_01: row.value.99_01,
                99_02: row.value.99_02,
                99_03: row.value.99_03,
                99_04: row.value.99_04,
                99_05: row.value.99_05,
                99_06: row.value.99_06,
                99_07: row.value.99_07,
                99_08: row.value.99_08,
                99_09: row.value.99_09,
                99_10: row.value.99_10,
                99_11: row.value.99_11,
                99_12: row.value.99_12,
                99_13: row.value.99_13,
                99_14: row.value.99_14,
                99_15: row.value.99_15,
                99_16: row.value.99_16,
                99_17: row.value.99_17,
                99_18: row.value.99_18,
                99_19: row.value.99_19,
                99_20: row.value.99_20,
                99_21: row.value.99_21,
                99_22: row.value.99_22,
                99_23: row.value.99_23,
                99_24: row.value.99_24,
                99_24_99: row.value.99_24_99,
                99_25: row.value.99_25,
                99_25_99: row.value.99_25_99,
                99_26: row.value.99_26,
                99_26_99: row.value.99_26_99,
                99_27: row.value.99_27,
                99_27_99: row.value.99_27_99,
                99_28: row.value.99_28,
                99_28_99: row.value.99_28_99,
                99_29: row.value.99_29,
                99_29_99: row.value.99_29_99,
                99_30: row.value.99_30,
                99_30_99: row.value.99_30_99,
                99_31: row.value.99_31,
                99_31_99: row.value.99_31_99,
                99_32: row.value.99_32,
                99_33: row.value.99_33,
                99_34: row.value.99_34,
                99_34_99: row.value.99_34_99,
                99_35: row.value.99_35,
                99_36_99: row.value.99_36_99,
                00_90_01_01: row.value.00_90_01_01,
                00_90_01_01_99: row.value.00_90_01_01_99,
                00_90_01_02: row.value.00_90_01_02,
                00_90_01_03: row.value.00_90_01_03,
                00_90_01_04: row.value.00_90_01_04,
                00_90_01_05: row.value.00_90_01_05,
                00_90_01_08: row.value.00_90_01_08,
                00_90_01_09: row.value.00_90_01_09,
                00_90_01_10: row.value.00_90_01_10,
                00_90_01_12: row.value.00_90_01_12,
                00_90_01_15: row.value.00_90_01_15

            });

        }

        send(JSON.stringify(results));

    });

}

我不能因为某些原因使这个列表工作,并且总是收到错误消息

  

{“error”:“compilation_error”,“reason”:“表达式不会评估为a   功能。 (function(head,req){provide('json',function(){var   results = []; while(row = getRow()){results.push({_ id:   row.value._id,_rev:row.value._rev,SomeType:row.value.SomeType,   taken_Date:row.value.taken_Date,taken_Time:row.value.taken_Time,   患者:row.value.Patient,护士:row.value.Nurse,SortNr:   row.value.SortNr,00_02:row.value.00_02,00_03:row.value.00_03,   00_03_99:row.value.00_03_99,00_04:row.value.00_04,00_05:   row.value.00_05,00_06:row.value.00_06,00_08:row.value.00_08,   00_10:row.value.00_10,00_10_99:row.value.00_10_99,00_14:   row.value.00_14,00_15:row.value.00_15,00_16:row.value.00_16,   00_17:row.value.00_17,00_18:row.value.00_18,00_19:   row.value.00_19,00_20:row.value.00_20,99_01:row.value.99_01,   99_02:row.value.99_02,99_03:row.value.99_03,99_04:   row.value.99_04,99_05:row.value.99_05,99_06:row.value.99_06,   99_07:row.value.99_07,99_08:row.value.99_08,99_09:   row.value.99_09,99_10:row.value.99_10,99_11:row.value.99_11,   99_12:row.value.99_12,99_13:row.value.99_13,99_14:   row.value.99_14,99_15:row.value.99_15,99_16:row.value.99_16,   99_17:row.value.99_17,99_18:row.value.99_18,99_19:   row.value.99_19,99_20:row.value.99_20,99_21:row.value.99_21,   99_22:row.value.99_22,99_23:row.value.99_23,99_24:   row.value.99_24,99_24_99:row.value.99_24_99,99_25:row.value.99_25,   99_25_99:row.value.99_25_99,99_26:row.value.99_26,99_26_99:   row.value.99_26_99,99_27:row.value.99_27,99_27_99:   row.value.99_27_99,99_28:row.value.99_28,99_28_99:   row.value.99_28_99,99_29:row.value.99_29,99_29_99:   row.value.99_29_99,99_30:row.value.99_30,99_30_99:   row.value.99_30_99,99_31:row.value.99_31,99_31_99:   row.value.99_31_99,99_32:row.value.99_32,99_33:row.value.99_33,   99_34:row.value.99_34,99_34_99:row.value.99_34_99,99_35:   row.value.99_35,99_36_99:row.value.99_36_99,00_90_01_01:   row.value.00_90_01_01,00_90_01_01_99:row.value.00_90_01_01_99,   00_90_01_02:row.value.00_90_01_02,00_90_01_03:   row.value.00_90_01_03,00_90_01_04:row.value.00_90_01_04,   00_90_01_05:row.value.00_90_01_05,00_90_01_08:   row.value.00_90_01_08,00_90_01_09:row.value.00_90_01_09,   00_90_01_10:row.value.00_90_01_10,00_90_01_12:   row.value.00_90_01_12,00_90_01_15:row.value.00_90_01_15}); }   发送(JSON.stringify(结果)); }); })“}

我真的不明白为什么第一个设计文档就像魅力一样,但第二个虽然很相似,但由于某种原因无法编译。

检查编码错误,多次重启东西..我只是出于想法,代码对我来说很好。

任何提示非常感谢:)

1 个答案:

答案 0 :(得分:2)

而不是

00_02: row.value.00_02,

'00_02': row.value['00_02'],

请注意,在这种情况下,自动类型确定不起作用。