How to specify the default context store in function node

I have in settings.js

    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?

Maybe this write up will help: A guide to understanding 'Persistent Context'

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.

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 :slight_smile:

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.

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

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

It fails if I have

    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.

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