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

138 Views Asked by At

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"])])

1

There are 1 best solutions below

2
On BEST ANSWER

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"])
)