如何在Azure COSMOS DB存储过程中将函数字符串转换为实函数

如何在Azure COSMOS DB存储过程中将函数字符串转换为实函数,azure,azure-cosmosdb,azure-cosmosdb-sqlapi,Azure,Azure Cosmosdb,Azure Cosmosdb Sqlapi,我想使用eval或函数构造函数在Azure Cosmos存储过程中动态创建函数 让我们举个例子: let fnStr = "function(){return 1; }" ; // string could contain any thing like a complex function 并希望在azure cosmos存储过程中使用 let fun =eval(fnStr); fun(); 但不幸的是,Azure cosmos不支持“eval”和“Function”构造函数 我们还有别的

我想使用eval或函数构造函数在Azure Cosmos存储过程中动态创建函数

让我们举个例子:

let fnStr = "function(){return 1; }" ; // string could contain any thing like a complex function
并希望在azure cosmos存储过程中使用

let fun =eval(fnStr);
fun();
但不幸的是,Azure cosmos不支持“eval”和“Function”构造函数


我们还有别的选择吗

您应该能够在存储过程体内编写适当的函数并调用它。例如,我编写了一个返回当前日期/时间的函数,然后从存储过程内部调用该函数。比如:

function helloWorld() {

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

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

这样做行吗?

我知道这是静态方式,但我的函数字符串可能来自azure cosmos文档,或者作为存储过程参数,只要文档位于同一逻辑分区中,您就可以了。存储过程的作用域是Cosmos DB中的逻辑分区。@MarkBrown我认为问题在于,考虑到
eval
new function
都不受支持,如何从字符串在存储过程中动态创建函数。你知道有没有什么方法可以使用require或import导入现有的节点模块(比如https)吗?啊,明白了。不,那是不可能的。