如何从Node-red msg.payload中选择Cloudant数据?

时间:2016-10-14 14:39:49

标签: ibm-cloud iot cloudant node-red watson-iot

我必须从cloudant数据库中读取数据。结果msg.payload的值如下:

[{"_id":"0de4df1286119588b8529a01ce7ae88c","_rev":"2-6702cf5c73c76536d403caaae37f9f99","payload":{"direction":"out","count":"-1","timestamp":"2016-10-06T13:25:24.262Z"}},{"_id":"1cf44a5241cc413a21920b069942851c","_rev":"1-f0f2271864d39b5ca633fe284590ae99","payload":{"direction":"out","count":"-1","timestamp":"2016-10-06T14:38:11.920Z"}},{"_id":"970049cb8ec6e3853d50f65f520ad385","_rev":"1-f7642fc0eab3938388138e04ce1d2c26","payload":{"direction":"IN","count":"1","timestamp":"2016-10-06T13:25:16.286Z"}}]

我想从上面的有效负载中选择所有_id。

I want to print only the _id from the payload using the debug node 我尝试使用msg.payload._id但它无法正常工作。它将结果显示为“{}”

1 个答案:

答案 0 :(得分:1)

问题是有效负载对象是一个数组对象(对于从数据库查询返回的结果集有意义)

您需要在调试节点输出过滤器中包含数组索引

.payload[0]._id

这将从数组中的第一个条目

中提供_id