我有一个功能节点,可以创建一个数组;有没有办法将所有条目存储在Cloudant数据库中?
感谢。
答案 0 :(得分:1)
看起来Node-RED仅支持Cloudant中的基本插入或删除操作 - 这意味着不支持_bulk_docs
端点(docs here)。
您可以使用HTTP请求功能通过API使用上面链接的文档发出您自己的{{1}}请求,这样您就可以一次插入多个文档。
答案 1 :(得分: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":[]}]
答案 2 :(得分:0)
如果保留阵列,可以使用拆分节点之类的东西将其分解为单独的消息,并一次插入1个。
或者更改您的功能节点以输出消息流,并再次一次插入一个消息。