Couchbase XDCR Advance filtering- How to configure dynamic date range in filter expression

80 views Asked by At

Is there any possible mechanism by which we can configure XDCR filter expression with dynamic date range in couchbase?

example can be like configuring filter expression for replicating entities older than year. DATE_DIFF_STR(NOW_STR(), createdDate,"day") > 365

As per documentation it seems N1QL date functions are not supported https://docs.couchbase.com/server/current/xdcr-reference/xdcr-filtering-expressions.html says "N1QL date functions are not supported by XDCR Advanced Filtering. For information on N1QL date functions, see the N1QL page for Date Functions"

Please suggest if any alternative of N1QL date function can be used while configuring XDCR filter expression to filter entities based on interval of time between the current date and the date of creation field in the given document.

1

There are 1 answers

0
Perry Krug On

Unfortunately you're not going to be able to achieve what you want with XDCR filtering. A document is replicated when it is added or changed, and the filter is evaluated at that time. Therefore, if a document's createdDate passes the 365 day mark but isn't subsequently updated, it won't be re-evaluated for replication.

I would suggest using the Eventing Service here which allows you to define a timer that will trigger at some point in the future. So in your case, when a document comes in, you would set a timer for createdDate+365. You can then configure a callback to do "whatever you want" - as an example, you could have it update the document with a "replicate=true" field which can then be filtered on in XDCR.