node.js - Azure Cosmos + Gremlin NodeJS,如何以脚本形式提交流畅的查询(不是字节码——我知道它还不支持)

标签 node.js azure gremlin azure-cosmosdb-gremlinapi

我正在尝试在nodejs中为cosmos db编写流畅的gremlin查询,即使它们作为字符串提交。我已经阅读了文档,并且在一些 github 线程中看到虽然尚不支持字节码,但可以将其作为脚本提交。

到目前为止我拥有的代码:

配置客户端功能:


export const CosmosConn = async (): Promise<driver.Client> => {
    try {
        const cosmosKey: string = await GetSecret('cosmos-key');
        const cosmosEndpoint: string = await GetSecret('cosmos-endpoint');

        const authenticator: driver.auth.PlainTextSaslAuthenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(
            '/dbs/main/colls/main',
            cosmosKey
        );
        const client: driver.Client = new gremlin.driver.Client(cosmosEndpoint, {
            authenticator,
            traversalsource: 'g',
            rejectUnauthorized: true,
            mimeType: 'application/vnd.gremlin-v2.0+json'
        });

        return client;
    } catch (err) {
        console.error(err);
    }
};

现在下面这两个是临时的,因为我会为每个查询等待几次 CosmosConn,但这是针对 Azure 函数的,所以我还没有优化:

export const Graph = async (query: gremlin.process.Bytecode): Promise<any> => {
    const db = await CosmosConn();
    const translator = new gremlin.process.Translator(
        new gremlin.process.AnonymousTraversalSource()
    );
    return db.submit(translator.translate(query));
};

export const getGremlin = async () => {
    const db = await CosmosConn();
    return gremlin.process.traversal().withRemote(db);
};

现在当我尝试使用它时:

    const g = await getGremlin();
        const query = g
            .V()
            .hasLabel('client')
            .getBytecode();

        const test = await Graph(query);

这当然会抛出一个错误:

Gremlin Query Syntax Error: Script compile error: Unexpected token: 'Object'; in input: '[objectObject'. @ line 1, column 9.

最佳答案

您是否尝试在提交之前打印translator.translate(query)

根据我的经验,翻译器对重要查询的支持非常有限。

据微软称,他们计划在 12 月 19 日支持 Fluent API,所以最好等待官方支持。

关于node.js - Azure Cosmos + Gremlin NodeJS,如何以脚本形式提交流畅的查询(不是字节码——我知道它还不支持),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58815569/

相关文章:

javascript - AJAX url路径问题

c# - 依赖关系未显示在应用程序 map 中?

gremlin - 如何使用 JanusGraph 中的属性值检索所有顶点?

azure - 无法删除 Azure 存储帐户

linux - msbuild.exe 无法在 Azure 中的 Linux VM 上运行

azure-cosmosdb - Gremlin 查询 Edge inVLabel、outVLabel

groovy - 使用 gremlin 查找距起始节点给定距离内的所有节点

javascript - 在 Mongoose 中,找不到模块 '\node_modules\ipaddr.js\lib\ipaddr.js' 。请验证 package.json 是否具有有效的 "main"条目

node.js - 如何依赖 Oauth2 身份验证流程对 Azure 应用程序进行性能/ping 测试?

Javascript 无法使用 fetch 捕获错误