Can't strore large variables in global context

I am trying to store a variable(string) around 6000 size in global context.

        let globalContext = this.context().global;
        globalContext.set("myData", stringData);

But the retrieved variable has only around 1000 characters.

Can't I/Shouldn't I store lage variables in theglobal context.

What is the proper way to store/retrieve a large variable globally?

If you retrieve that large variable and send it to a debug node, then the debug node will only show the first 1000 characters or so -- this does not mean that the global context is incorrect. To verify that what you get out is the same a what you put into the context, check the box on the debug node labelled "system console" and you will see the same data is printed in the console log (strangely enough!)

2 Likes

Incidentally, I just checked the info sidebar for the debug node and was surprised to see that there is no mention of the displayed data being truncated at xxx bytes -- or how to view the full msg data. It does say the "status" msgs will be truncated at 32 chars. Perhaps the sidebar max settings would be a good thing to note as well...

If you are storing it using filesystem, then you could check it by looking in the .node-red folder and then in the context folder then to the global folder and check it out there.

Thank you for the response. I tried again and ended up with the same result.

I will show my code.

Following is the part of the code where I set the global context variable.

            let globalContext = this.context().global;
            console.log("Stored data length " + temp.length);
            globalContext.set("MyData", temp);

Here I got 6374 characters in the stored message.

I retrieve this context variable in my side bar. Following is a simple version of the code.

data["memory"]["MyData"]["msg"].length which gives 1003 characters.

While debugging I captured the object.

{MyData: {…}}
MyData:
format: "string[6792]"
msg: "{"xxxx..."
__proto__: Object
__proto__: Object

And there I can see the msg holds data but it has ... indicating more data which is not there.

Is there any problem in my storing or retrieving code?
​​​

As has been explained, the Debug sidebar only shows the first 1000 bytes of data. The same is true of the Context sidebar.

This is why it has been suggested you write the data to a file to independently verify its contents.

I got the result on the browser debug window.

Problem is getting an incorrect length for the length of retrieved data.

data["memory"]["MyData"]["msg"].length

How are you writing the data to the browser debug window? Where has data come from?

I am on the front end of my side bar. In sidebar HTML, in a script, I am calling the context/global API endpoint

$.getJSON('context/global', function (data) {
        for (var store in data) {
            if (data.hasOwnProperty(store)) {
                if (data[store].hasOwnProperty('MyData'))                 
                 content = data[store]['MyData']['msg'];

What I didn't spell out in this reply, is the Context sidebar uses the /context api ... so the actual truncation is in that API. If you are using that API, you will get truncated data.

What are you using the global context for in your custom sidebar?

I have one node which aggregates a content. Once the content is ready, I am using a button in the sidebar to send that content to remote endpoint. In this scenario, I store the content in the global context variable to make it visible to the call perform in the sidebar. Simply I need to write data from a flow node and access it from my sidebar.

If it isn't data to be used in the flow itself, can you not store it in a local variable within your code and add your own custom admin http end point for your sidebar to call?

Yes, that would be possible, Thank you very much for pointing it out.

I used the global context storage as I thought it is the best way. Anyway I will proceed with creating an admin endpoint.