Botti
Botti

Reputation: 1

Can the Atlas search filter in MongoDB cloud be used to query between dates?

All the examples I read online seem to refer to using the compass or the command line, not MongoDB cloud. I try emulate the same query code in the search filter but not having any luck.

Search function

For example with the sample collections..

_id:ObjectId("5bd761dcae323e45a93ccff1")
saleDate:2014-08-18T04:37:26.849+00:00
storeLocation:"Denver"
couponUsed:false
purchaseMethod:"In store"


_id:ObjectId("5bd761dcae323e45a93ccff7")
saleDate:2017-12-08T21:40:34.527+00:00
storeLocation:"Denver"
couponUsed:false
purchaseMethod:"Phone"


_id:ObjectId("5bd761dcae323e45a93ccfef")
saleDate:2014-03-31T16:02:06.624+00:00
storeLocation:"Austin"
couponUsed:false
purchaseMethod:"Online"

How could I filter saleDate to show objects from 2014?

Upvotes: 0

Views: 724

Answers (1)

Nice-Guy
Nice-Guy

Reputation: 1524

Botti you want to use the range operator in $search pipeline:

{
    "$search": {
       "index": "<index Name>",
       "range": {
          "path": "saleDate",
          "gte":"2014-03-31T16:02:06.624+00:00",
          "lte": "2017-12-08T21:40:34.527+00:00"
       }
    }
}

Upvotes: 1

Related Questions