# How to specify the default context store in function node

**URL:** <https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859>\
**Category:** General\
**Created:** [27 January 2021 10:47 UTC](https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859 "2021-01-27T10:47:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 10:47 UTC](https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859/1 "2021-01-27T10:47:35Z")

</div>

I have in settings.js

```auto
    contextStorage: {
        default: "memoryOnly",
        memoryOnly: { module: 'memory' },
        file: { module: 'localfilesystem' }
    },

```

and in a function node I can access memoryOnly or file by using, for example  
`context.get("x", "memoryOnly")`  
However, if I use `context.get("x", "default")`, it says  
`[warn] Unknown context store 'default' specified. Using default store.`

I want to do this as it is used in a subflow and the store to use is one of the env parameters. It would be nice to have a default there of "default" rather than "memoryOnly" which might not even be a valid store. I can do it with a hack by testing for "default" and using `null` if it is but that isn't very pleasing.  
Am I missing something?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 January 2021 16:50 UTC](https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859/2 "2021-01-27T16:50:55Z")

</div>

Maybe this write up will help: [A guide to understanding 'Persistent Context'](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 17:02 UTC](https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859/3 "2021-01-27T17:02:17Z")

</div>

Do you mean that my contextStorage spec is invalid? I agree that the syntax used is not shown in the guide, but everything works perfectly well except that I am not able to _explicitly_ select default in a `context.set/get` call.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [27 January 2021 17:03 UTC](https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859/4 "2021-01-27T17:03:41Z")

</div>

> [@Colin](#):
>
> want to do this as it is used in a subflow and the store to use is one of the env parameters. It would be nice to have a default there of "default" rather than "memoryOnly" which might not even be a valid store.

Good question Colin - I'm not entirely surprised that it doesn't like you saying `default`. I can well imagine I would have rationalised this as "well, if they want the default, just don't specify a store". But I can see how that wouldn't support what you're trying to do.

I have added an item to the whiteboard for this. You're doing very well for finding these little things to improve - very much appreciated 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 17:09 UTC](https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859/5 "2021-01-27T17:09:23Z")

</div>

> [@knolleary](#):
>
> I can well imagine I would have rationalised this as "well, if they want the default, just don't specify a store"

I wonder if it is that or if it is that I have got  
`default: "memoryOnly",`  
so effectively a level of indirection is involved. Perhaps if I had  
`default: {module: 'memory'},`  
it would work. I will check it out tomorrow.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 21:29 UTC](https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859/6 "2021-01-27T21:29:13Z")

</div>

I can confirm that using  
`context.get("x", "default")`  
works ok if settings.js contains

```auto
    contextStorage: {
        default: { module: 'memory' },
        file: { module: 'localfilesystem' }
    },

```

It fails if I have

```auto
    contextStorage: {
        default: "memoryOnly",
        memoryOnly: { module: 'memory' },
        file: { module: 'localfilesystem' }
    },

```

It also fails if I don't specify contextStorage at all in settings.js, which is perhaps not surprising.

---

<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:** [28 March 2021 21:30 UTC](https://discourse.nodered.org/t/how-to-specify-the-default-context-store-in-function-node/39859/7 "2021-03-28T21:30:11Z")

</div>

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