# Persistent global context - missing variables

**URL:** <https://discourse.nodered.org/t/persistent-global-context-missing-variables/42146>\
**Category:** General\
**Created:** [6 March 2021 12:38 UTC](https://discourse.nodered.org/t/persistent-global-context-missing-variables/42146 "2021-03-06T12:38:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [6 March 2021 12:38 UTC](https://discourse.nodered.org/t/persistent-global-context-missing-variables/42146/1 "2021-03-06T12:38:49Z")

</div>

I am using around 30 persistent global variables saved in my local Store.  
Today I had to restart the Raspi after a kernel update and after restart I found that 5% of the variables were set as "undefined", not stored in the context.  
This is not the first time it happens. How can I rely on the persistent global storage?

This is my settings.js:

```auto
 contextStorage: {
        lilioStore: { module: "localfilesystem"},
        lilioStoreLuci: { module: "localfilesystem"},
        default : { module: "memory" }
    },

```

and I am setting the variables with :

```auto
global.set("variable-name", value,"lilioStore");

```

Everything looks very straightforward.

---

<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:** [6 March 2021 13:24 UTC](https://discourse.nodered.org/t/persistent-global-context-missing-variables/42146/2 "2021-03-06T13:24:16Z")

</div>

You still have two local filesystem stores where you have not given them different directories.

That is going to cause problems. Until you fix that, it isn't worth investigating anything else.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [6 March 2021 15:02 UTC](https://discourse.nodered.org/t/persistent-global-context-missing-variables/42146/3 "2021-03-06T15:02:41Z")

</div>

Yes, I am studying how to separate them without losing variable states...  
How can I extract all variables from a store?

---

<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:** [6 March 2021 15:21 UTC](https://discourse.nodered.org/t/persistent-global-context-missing-variables/42146/4 "2021-03-06T15:21:06Z")

</div>

> [@fmarzocca](#):
>
> Can I extract all variables from a store?

There was a thread on this very recently (like 1 or 2 days ago)

However, IMHO, it is better store related global (or flow) values in a single object.

```auto
config = {
    "ip": "1.2.3.4",
    "enabled": true,
    "params": [5, 33, 123, 54],
    "maintainer": {
        "name": "fred",
        "email": "fred@here.com"
    }
}

```

That way it is a simple matter of `var config = global.get("config")`(or the change node equivelant)

and you can access `config.ip` and `config.enabled` etc.

Additionally, as well as all values being neatly "packaged" in one object, you can click the `copy value` button on the global viewer in the side-bar & get all values in one go (manual backup if you like)

![0Lz4dg0gHn](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/5316f0d1187f468e1e63d0f3454781dd4052fdb4.gif)

↑ Feel free to ignore this if this is of no value 🙂 (its just a suggestion)

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [6 March 2021 15:32 UTC](https://discourse.nodered.org/t/persistent-global-context-missing-variables/42146/5 "2021-03-06T15:32:52Z")

</div>

I think I will move all variables from a store into the other, and then remove the first store, so I will have just one:

```auto
a = global.keys("lilioStoreLuci");

for (var x in a) {
    temp = global.get(a[x],"lilioStoreLuci");
    global.set (a[x],temp,"lilioStore");
    global.set (a[x],undefined,"lilioStoreLuci")
}

```

removing it also from settings.js

---

<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:** [5 May 2021 15:50 UTC](https://discourse.nodered.org/t/persistent-global-context-missing-variables/42146/7 "2021-05-05T15:50:28Z")

</div>

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