0

This question is similar to: MarkLogic - XQuery - cts:element-range-query using variable length sequence or map

But this time I need to do the query using the queryBuilder in the node.js client API.

I have a collection of 100,000 records structured like this:

<record>
    <pk>1</pk>
    <id>1234</id>
</record>
<record>
    <pk>2</pk>
    <id>1234</id>
</record>
<record>
    <pk>3</pk>
    <id>5678</id>
</record>
<record>
<pk>4</pk>
    <id>5678</id>
</record>

I have setup a range index on id.

I want to write a query using the queryBuilder node.js client API that will allow me to pass in an array of IDs and get out a list of records.

It needs to: 1) query a specific collection 2) leverage the range indexes for performance

1 Answer 1

2

Nevermind, I figured out the problem.

db.db.documents.query(
  q.where(
    q.collection('Records'),
    q.or(
        q.value('id', ['1', '2'])
    )
  ).slice(1, 99999999)
)

I originally tried to pass an array into q.value and I was only getting limited results (Got 10 when I expected 20). So I was under the impression that I was doing it wrong.

It turns out I just needed to slice the where clause to include everything. Apparently if you don't specify how much to take it defaults to 10.

Also note that when I tried .slice(0) which would have been preferred, I got an exception.

Sign up to request clarification or add additional context in comments.

1 Comment

Because the database can contain many more documents than would be practical to retrieve in a single request, you should specify the largest number of documents you're willing to retrieve -- so your solution is correct; btw, .slice(0) returns no documents, which you would typically do only if getting facets.

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.