使用 Marklogic node.js 查询生成器仅获取 json 文档

Get only json documents using Marklogic node.js query builder

在我的 Marklogic 数据库中,我有混合文档格式。我只想从集合中获取 JSON 文档。 我有一个像这样的查询生成器语句

    const documents = await dbClient.documents
        .query(
            qb
                .where(qb.collection('myCollection'))
                .slice(0, 10)
        )
        .result();

是否可以在此处使用一些过滤器来仅获取 JSON 个文档?

我无法快速测试以下内容,但确实浏览了一些文档。根据这些文档,您应该能够使用 .withOptions(). That method's search option supports all of cts:search's options 指定文档格式,其中包括在您的情况下通过“format-FORMAT”或 format-json 指定文档格式。

const documents = await dbClient.documents
    .query(
        qb.where(qb.collection('myCollection'))
          .withOptions({search: ['format-json']})
          .slice(0, 10)
    )
    .result();