marklogicmarklogic-dhf

How to select documents using cts query that are in CollectionA and not in CollectionB


I am pretty new to using cts queries so I need some help with something that is, I would think, pretty simple. I need to select document that are in CollectionA but are not in CollectionB. How would I modify the below query to insure the documents that are in CollectionB are not selected:

cts.andQuery([cts.fieldRangeQuery('datahubCreatedOn', '>=', xs.dateTime(fn.currentDateTime()).subtract(xs.duration('PT120M'))),  cts.collectionQuery(["CollectionA"])])


Solution

  • I would use a cts.andNotQuery()

    cts.andNotQuery(
      cts.andQuery([
        cts.fieldRangeQuery('datahubCreatedOn', '>=', xs.dateTime(fn.currentDateTime()).subtract(xs.duration('PT120M'))),  
        cts.collectionQuery(["CollectionA"])
      ]),
      cts.collectionQuery(["CollectionB"])
    )