# Enterprise Search Mongo-Connector Advanced Rule to Filter by Current Date

**URL:** <https://discuss.elastic.co/t/enterprise-search-mongo-connector-advanced-rule-to-filter-by-current-date/332660>\
**Category:** Elastic Search\
**Tags:** elastic-workplace-search\
**Created:** [May 5, 2023, 2:45pm UTC](https://discuss.elastic.co/t/enterprise-search-mongo-connector-advanced-rule-to-filter-by-current-date/332660 "2023-05-05T14:45:03Z")\
**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:** [May 5, 2023, 2:45pm UTC](https://discuss.elastic.co/t/enterprise-search-mongo-connector-advanced-rule-to-filter-by-current-date/332660/1 "2023-05-05T14:45:03Z")

</div>

Hello! I am trying to ingest records from MongoDB through a Enterprise Search Mongo-Connector. I would like to use an advanced rule to only pull in those where a specific field (`expiresAt`) is greater than or equal to the current date. The Elastic docs state that the mongodb connector supports aggregation pipelines in the advanced rules, however I am getting errors when trying to set this up.

For example:

```auto
{
  "aggregate": {
    "pipeline": [
      {
        "$addFields": {
          "current_date": { "$toDate": "$$NOW" }
        }
      },
      {
        "$match": {
          "expiresAt": {
            "$gte": "$current_date"
          }
        }
      }
    ]
  }
}

```

Throws the following error:

```auto
[40324:Location40324]: Unrecognized pipeline stage name: '$add_fields' (on server-shard-00-01.o4mny.mongodb.net:27017, modern retry, attempt 1)

```

Where is it even getting "add\_fields" from? Is this not possible?

---

<div class="post-metadata">

**Author:** ![Tim\_Grein](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_grein/32/121657_2.png) [@Tim\_Grein](https://discuss.elastic.co/u/Tim_Grein)\
**Post date:** [May 31, 2023, 8:41am UTC](https://discuss.elastic.co/t/enterprise-search-mongo-connector-advanced-rule-to-filter-by-current-date/332660/2 "2023-05-31T08:41:34Z")

</div>

Hi Colin,

Thank you for your message! May I ask you, which version of connectors/Enterprise Search you're using?

---

<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:** [May 31, 2023, 2:37pm UTC](https://discuss.elastic.co/t/enterprise-search-mongo-connector-advanced-rule-to-filter-by-current-date/332660/3 "2023-05-31T14:37:10Z")

</div>

Hi Tim,  
After talking to support for awhile, it turned out this was a known issue with 8.7. Now that I have upgraded everything to 8.8, this advanced rule is working. From support:

> the reason for the underscore demarcated add\_fields is just that we internally convert everything from camel-case to snake-case in our implementation. The actual error you encountered, however, is an issue with our 8.7 release.

---

<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:** [June 28, 2023, 2:38pm UTC](https://discuss.elastic.co/t/enterprise-search-mongo-connector-advanced-rule-to-filter-by-current-date/332660/4 "2023-06-28T14:38:05Z")

</div>

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