2
votes

I am using MarkLogic Node.js Client API. I am running a query in which I want to specify multiple collections; but I am getting zero results. However, if I specify just one collection; the query works. Below is the example with one collection:

Collections: test1 and test2

Query with 1 collection: Works

db.documents.query(
        qb.where(
            qb.collection("test1"),
            qb.value("productId","8989")
        ))
        .result();

Please help as how I can specify two collections?

Below query returns zero results:

db.documents.query(
        qb.where(
            qb.collection("test1"),qb.collection("test2"),
            qb.value("productId","8989")
        ))
        .result();
1

1 Answers

4
votes

By "fails", do you mean that the query returns no results, or an error?

Constraints in qb.where are and'd together, so the following only matches documents in both collections:

qb.where(
  qb.collection("test1"),
  qb.collection("test2")
)

To match documents in either collection, you need an or query:

qb.where(
  qb.or(
    qb.collection("test1"),
    qb.collection("test2")
  )
)