Azure Cosmos DB 在存储过程中解码 base64

Azure Cosmos DB decode base64 in stored procedure

我需要在 Azure CosmosDB 的存储过程中解码 base64 编码的字符串。我尝试使用以下函数,但对于每个函数,我都收到未定义错误:

我最终使用 this algorithm 创建了一个自定义函数,但这似乎不是一个好的做法。

是否有内置函数?

var defaultGroupId = groupIds.filter(id => {
    // atob(id); base64_decode_tostring(id); are not working
    let decoded = base64_decode(id);
    return decoded.indexOf(defaultGroupIndicator) == 0;
});

function base64_decode(s) {
    // took from the link above;
}

除了作为 JS 规范本身的一部分提供的方法之外,我们不提供实用方法。 btoa 和 atob 不是其中的一部分。如果您需要此功能,那么最好(唯一)的选择是使用任何可用的开源实现。

我还想指出,如果您使用存储过程进行大量读取,您可能需要重新考虑这一点。执行大量批量写入时最好使用存储过程。存储过程仅对我们的四个副本集中的主副本进行操作。因此,当您的所有读取都在主副本上并且不使用任何辅助副本时,您将看不到所有配置的吞吐量。

希望对您有所帮助。