2016-11-23 76 views

回答

1

以下是使用http請求節點的示例流程,基於https://docs.cloudant.com/document.html#bulk-operations

[{"id":"b97b6381.90cd18","type":"inject","z":"b4aeef03.c16228","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":95.5,"y":330,"wires":[["accfba5c.0df688"]]},{"id":"accfba5c.0df688","type":"function","z":"b4aeef03.c16228","name":"Multiple records to insert","func":"msg.payload = {\n \"docs\": [\n {\n  \"name\": \"Nicholas\",\n  \"age\": 45,\n  \"gender\": \"female\"\n },\n {\n  \"name\": \"Taylor\",\n  \"age\": 50,\n  \"gender\": \"female\"\n }\n ]\n}\n\nmsg.headers={\"Content-Type\":\"application/json\"}\n\nreturn msg;","outputs":1,"noerr":0,"x":357.9000244140625,"y":331.5999755859375,"wires":[["a950d685.dcf92"]]},{"id":"a950d685.dcf92","type":"http request","z":"b4aeef03.c16228","name":"Bulk add to Cloudant","method":"POST","ret":"txt","url":"https://REPLACE-bluemix.cloudant.com/dev/_bulk_docs","x":636.9000244140625,"y":330.79998779296875,"wires":[["e2355dc3.e1118"]]},{"id":"e2355dc3.e1118","type":"debug","z":"b4aeef03.c16228","name":"","active":true,"console":"false","complete":"false","x":888.9000244140625,"y":329.79998779296875,"wires":[]}] 

enter image description here

1

看起來Node-RED只支持Cloudant中的基本插入或刪除操作 - 這意味着不支持_bulk_docs端點(docs here)。

您可以使用HTTP請求功能通過API使用上面鏈接的文檔製作您自己的_bulk_docs請求,這應該允許您一次插入多個文檔。

0

如果你保留數組,你可以使用類似分裂節點的東西將它分解成單獨的消息並一次插入1個。

或者更改您的功能節點以輸出消息流,並再次將它們插入一次。

相關問題