# MQTT in node: subscription to array of topics with MQTT wildcards

**URL:** <https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304>\
**Category:** General\
**Tags:** mqtt\
**Created:** [16 February 2023 15:37 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304 "2023-02-16T15:37:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [16 February 2023 15:37 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304/1 "2023-02-16T15:37:31Z")

</div>

Hello,  
According to the documentation of the MQTT in node, the subscription can be an array of strings. So something like `["abcd/#" , "defg/#"] ` as a subscription should be valid.  
However if any topic include an MQTT wildcard `#` or `+` within an array I have the "you've done something wrong" red triangle on the node.  
If I use the dynamic subscription and push the same array using `msg.topic` (with the action being subscribe) everyone is happy.  
Any reason why I can't have such an array directly in the node?  
Thanks!!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 February 2023 15:49 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304/2 "2023-02-16T15:49:35Z")

</div>

> [@greengolfer](#):
>
> According to the documentation of the MQTT in node, the subscription can be an array of strings. So something like `["abcd/#" , "defg/#"] ` as a subscription should be valid.

In the help text it says under dynamic subscription

> Inputs
> 
> These only apply when the node has been configured for dynamic subscriptions.

So i would read that as you can use an array of string for dynamic subscriptions only.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [16 February 2023 16:41 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304/3 "2023-02-16T16:41:16Z")

</div>

I get your point the array is described in the dynamic section. So, maybe, that is the intention for the "static" configuration to accept only a single topic...  
However, an array without wildcards in the "topic" field works.  
So, it is a bit of both 🙂  
Array in static works, but no wildcard.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2023 17:42 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304/4 "2023-02-16T17:42:02Z")

</div>

> [@greengolfer](#):
>
> Array in static works, but no wildcard.

That is not doing what you think.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78889e530ddd629eb4a739d9c548b461121e5770.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d118bab765850ac8d9f1c671fe2b089dd15fde9b.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2023 17:45 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304/5 "2023-02-16T17:45:40Z")

</div>

> [@greengolfer](#):
>
> So something like `["abcd/#" , "defg/#"] ` as a subscription should be valid.

No, the static input is a single string topic. It is not parsed to be an array or anything except a string. WYSTIWTBITTST (What You Subscribe To Is What The Broker Is Told To Subscribe To)

The reason `["abcd/#" , "defg/#"]` is shown as invalid is because `#` must be the last item in a topic path.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [16 February 2023 17:49 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304/6 "2023-02-16T17:49:22Z")

</div>

So in my example, it is in fact listening to a topic including the opening [and the closing] altogether and consider this "array" as one string?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2023 17:52 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304/7 "2023-02-16T17:52:20Z")

</div>

That is correct. you are subscribing to exactly 1 topic - the topic you entered whether that includessquare brackets, commas or not

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 April 2023 17:52 UTC](https://discourse.nodered.org/t/mqtt-in-node-subscription-to-array-of-topics-with-mqtt-wildcards/75304/8 "2023-04-17T17:52:52Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
