Cosmos 存储过程 - console.log 问题

Cosmos Stored Procedure - console.log issue

我是 Cosmos DB 存储过程的新手。据介绍,cosmos存储过程是用Javascript写的,不能通过设置断点来调试,所以我们只好用console.log(...)查看存储过程中的元素内容。这是我的一个示例,它是根据输入参数 prefix(我的项目中的 'id' 属性)从我的集合中检索项目,以及使用 javascript-query-api

function example(prefix) {
    //not working with ','
    //console.log('input prefix: ', prefix);
    //this works with '+'
    console.log('input prefix: ' + prefix);
    var collection = getContext().getCollection();
    //cannot view what's collection represents
    console.log('collection:' + JSON.stringify(collection));
    collection.chain().filter(function (doc) {
        //un-comment below will make the console log blank...
        //console.log('inside filter prefix: ' + prefix);
        return doc.id == prefix;
    }).map(function (doc) {
        return {
            id: doc.id,
            price: doc.price
        }
    }).value();
}

这是我的console.logwindow

我的 console.log 不会换行或使用逗号 ',':

我遇到的几个问题总结如下:

数据架构:

存储过程执行细节:

存储过程结果和console.log:

  1. console.log inside the stored procedure won't work with comma - , but only works with colon - :

是的,实际上它只适用于+,所以请使用+来合并日志信息。

  1. console.log won't do a line break...even I add \n inside...

如果您观察门户控制台中日志的输出,整个日志信息显示为一长串。因此,即使您添加 \n,它也被识别为字符串的一部分。您可以添加一些特殊字符,例如 ***----- 来区分。

  1. I cannot get what's really inside the collection object even I've deserialized it, as you can see from screenshot it's shown as {\"spatial\":{}}

由于 SP 是 运行 在服务器端,我相信我们不能像本地 sdk 一样访问每个对象。基于列出的陈述 here:

为特定集合注册了存储过程和触发器。集合对象支持对当前集合中文档和附件的创建、读取、更新和删除(CRUD)和查询操作。

我们可以将集合更多地视为调用 CRUD 的基础对象 methods.Like sdk 中用于调用方法的 init 客户端。

  1. If I wanted to look into what the input parameter - prefix passing inside my filter function, when I un-comment my console.log('inside filter prefix: ' + prefix);, then my console log screen will show only an empty string somehow which is really ...

测试你的代码,内部前缀日志确实有效。