How do I delete an object

2,549 views
Skip to first unread message

Toshi Bass

unread,
Sep 22, 2017, 11:20:34 AM9/22/17
to Node-RED
I have a Big Timer node, after I have used the information I need I want to delete this object in a function node and then pass a msg.payload to nodes further along the flow

Currently the msg.payload gets passed along the flow but so does all the status stuff, which is causing me a issue, so could some on give me a clue how I can delete this object please.

22/09/2017, 16:09:57node: 33255794.940458status : msg : Object
object
templateScope"local"
payload"On"
reference":1:0:969"
topic"status"
state"OFF Auto"
time"03hrs 31mins"
name"Timer"
start1180
end30
dusk1180
dawn377
solarNoon778
sunrise411
sunset1145
night1264
nightEnd293
now969
timer0
onOverride-1
offOverride-1
socketid"p-a7DEwTHiTKxvJZAAAF"
_msgid"6cc738e0.b1a628"

Nick O'Leary

unread,
Sep 22, 2017, 11:21:47 AM9/22/17
to Node-RED Mailing List
A Change node with a 'delete' rule.

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/a26ef22e-81f3-4dec-8bd1-53b461ab2158%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Toshi Bass

unread,
Sep 22, 2017, 11:58:11 AM9/22/17
to Node-RED
ok I tried a change node with delete rule but what do I put msg field, thought it might work with Object or status but nope all the stuff still gets through I am just not getting this...
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Nick O'Leary

unread,
Sep 22, 2017, 12:00:25 PM9/22/17
to Node-RED Mailing List
If you want to delete a property called msg.status, then configure the node to delete msg.status. There isn't much else to get about it.

The only question is making sure you know what property you want to delete.

Nick

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Toshi Bass

unread,
Sep 22, 2017, 12:10:06 PM9/22/17
to Node-RED
oh so I need to delete each of the 21 properties individually each on a separate line of the change node?... is there no way to delete the whole object in the change node or indeed in a function node   

Colin Law

unread,
Sep 22, 2017, 12:13:14 PM9/22/17
to node...@googlegroups.com
In a function node, instead of passing on the original message you can
make a new one
var newMsg={topic:msg.topic, payload:msg.payload}
return newMsg

Colin
> https://groups.google.com/d/msgid/node-red/a147c938-515f-4a97-b38b-02b30bd81184%40googlegroups.com.

Toshi Bass

unread,
Sep 22, 2017, 12:37:50 PM9/22/17
to Node-RED
That's it perfect, I've been struggling with this all afternoon, thanks you so much.


Nick O'Leary

unread,
Sep 22, 2017, 12:41:54 PM9/22/17
to Node-RED

No.

If you want to delete msg.status then just delete msg.status.

If you're struggling with that, share more specific details of what you've tried and what you see.

Nick


On Fri, 22 Sep 2017, 17:37 Toshi Bass <toshib...@gmail.com> wrote:
That's it perfect, I've been struggling with this all afternoon, thanks you so much.


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

steve rickus

unread,
Sep 22, 2017, 1:39:02 PM9/22/17
to Node-RED
The original post shows a full msg object with _msgid, topic, payload, and 19 other fields that are no longer needed. I was hoping to use a change node to delete every field EXPECT for a given list of names -- using this JSONata expression:

["_msgid", "topic", "payload"] {
 $
: $lookup($$, $)
}

HOWEVER, the change node's "Set" option do not allow the entire msg object to be replaced with the results of the expression. Bummer. But I guess I can see where replacing the whole msg object in-flight could get messy...

So, I would have to agree with Colin that the best way to "clean up" this msg object would be to build a new msg in a function node. I know that nodes should pass through the original msg (to preserve msg ids, http headers, split indexes, etc.) -- but putting 19 deletes in a change node is just ugly.
--
Steve

Colin Law

unread,
Sep 22, 2017, 5:06:27 PM9/22/17
to node...@googlegroups.com
Why does it matter that the other fields are there? If you do not use
them they will not cause problems, and any that you do need you can
setup with your function node or change node or whatever.

Colin

On 22 September 2017 at 17:10, Toshi Bass <toshib...@gmail.com> wrote:
> https://groups.google.com/d/msgid/node-red/a147c938-515f-4a97-b38b-02b30bd81184%40googlegroups.com.

Toshi Bass

unread,
Sep 23, 2017, 12:39:48 PM9/23/17
to Node-RED
I'm not sure if this question was aimed at me the original poster or not, but in reality Colin's answer  var newMsg={topic:msg.topic, payload:msg.payload}  return newMsg resolves my problem perfectly, the reason it matters is that I am back feeding a template node (a bit like a text node but it works as a button as well) it displays the start time or stop time information from the Big Timer node however when I press the display I needed to send "Timer Off" or "Timer On" back to that on the template node as you can imagine if I send a msg.payload of "Off"  and include all the Big Timer information as well it it ends up re-displaying the Big Timer info, when I send newMsg."Off" then it works perfectly.

Colin Law

unread,
Sep 23, 2017, 12:45:06 PM9/23/17
to node...@googlegroups.com
OK. Just checking that you were not just deleting the rest because you
thought it might cause a problem (in most cases extraneous fields will
not be a problem as following nodes will not look for them.

Coin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/3c6e3092-6a10-4cf5-80cd-168dd8b90795%40googlegroups.com.

Colin Law

unread,
Sep 23, 2017, 12:47:21 PM9/23/17
to node...@googlegroups.com
By the way, you can tell who the reply was aimed at by looking at the
message I replied to. In this case one from yourself. Provided I have
include the previous post in the reply which I always will.

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/3c6e3092-6a10-4cf5-80cd-168dd8b90795%40googlegroups.com.

Toshi Bass

unread,
Sep 23, 2017, 1:07:15 PM9/23/17
to Node-RED
OK thanks again
Capture.JPG
Reply all
Reply to author
Forward
0 new messages