1

In my Marklogic DB I have mixed documents formats. And I would like to get only JSON documents from the collection. I have a query builder statement like this

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

Is it possible to use some filter here to get only JSON documents?

1 Answer 1

3

I'm not in a position to quickly test the following, but did walk the docs a bit. Per those docs, you should be able to specify the document format using .withOptions(). That method's search option supports all of cts:search's options, which includes specifying the document format via "format-FORMAT", or format-json, in your case.

const documents = await dbClient.documents
    .query(
        qb.where(qb.collection('myCollection'))
          .withOptions({search: ['format-json']})
          .slice(0, 10)
    )
    .result();
Sign up to request clarification or add additional context in comments.

1 Comment

It works as expected! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.