# How to do Advanced Sync Rules on Date field with Relative Date for MongoDB

**URL:** <https://discuss.elastic.co/t/how-to-do-advanced-sync-rules-on-date-field-with-relative-date-for-mongodb/328853>\
**Category:** Elastic Search\
**Tags:** elastic-workplace-search\
**Created:** [March 29, 2023, 5:19pm UTC](https://discuss.elastic.co/t/how-to-do-advanced-sync-rules-on-date-field-with-relative-date-for-mongodb/328853 "2023-03-29T17:19:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pocketcolin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pocketcolin/32/117585_2.png) [@pocketcolin](https://discuss.elastic.co/u/pocketcolin)\
**Post date:** [March 29, 2023, 5:19pm UTC](https://discuss.elastic.co/t/how-to-do-advanced-sync-rules-on-date-field-with-relative-date-for-mongodb/328853/1 "2023-03-29T17:19:43Z")

</div>

I am trying to setup a MongoDB index sync that pulls over all records where a date field is `$gte` the current date. I assumed something like the following would work as it worked on the Mongo command line, but alas it pulled in 0 records:

```auto
{
  "aggregate": {
    "pipeline": [
      {
        "$match": {
          "expiresAt": {
            "$gte": "new Date()"
          }
        }
      }
    ]
  }
}

```

My hunch is that it's trying to do `new Date()` as a string literal and not actually evaluating that function. I've also tried doing `"$gte": "now"` but that doesn't work either. Is what I'm trying to do here possible?

_System_  
Host: ElasticCloud  
Elasticsearch Version: 8.6.2

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 30, 2023, 11:12pm UTC](https://discuss.elastic.co/t/how-to-do-advanced-sync-rules-on-date-field-with-relative-date-for-mongodb/328853/2 "2023-03-30T23:12:48Z")

</div>

Is this "index sync" a mongo concept? I haven't seen it in Elasticsearch.

EDIT - oh is this Enterprise Search?

---

<div class="post-metadata">

**Author:** ![pocketcolin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pocketcolin/32/117585_2.png) [@pocketcolin](https://discuss.elastic.co/u/pocketcolin)\
**Post date:** [March 31, 2023, 1:52pm UTC](https://discuss.elastic.co/t/how-to-do-advanced-sync-rules-on-date-field-with-relative-date-for-mongodb/328853/3 "2023-03-31T13:52:52Z")

</div>

Yes, sorry should have specified! This is Enterprise Search.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 28, 2023, 1:53pm UTC](https://discuss.elastic.co/t/how-to-do-advanced-sync-rules-on-date-field-with-relative-date-for-mongodb/328853/4 "2023-04-28T13:53:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
