2
votes

I want to create function dynamically in Azure Cosmos stored procedure using eval or Function constructor.

Let's have an example :

let fnStr = "function(){return 1; }" ; // string could contain any thing like a complex function

And want to use inside the azure cosmos stored proc

let fun =eval(fnStr);
fun();

But unfortunately, Azure cosmos does not support "eval" and "Function" constructor.

Do we have any alternatives?

1

1 Answers

0
votes

You should be able to write a proper function inside your stored procedure body and invoke it. For example I wrote a function which returns current date/time and then invoked that function from inside stored procedure. Something like:

function helloWorld() {

    function getCurrentDate() {
        return new Date();
    }

    var xyz = getCurrentDate();
    var response = getContext().getResponse();
    response.setBody(xyz);
}

Wouldn't something like this work?