Home > database >  Date range in mongodb atlas search using queryString is not working
Date range in mongodb atlas search using queryString is not working

Time:11-05

I tried this but with no success (I got an empty result):

{
    queryString: {
      defaultPath: 'anyfield',
      query: 'createdAt:["2000-01-30T20:19:53.123Z" TO *]'
    }
}

I tried with no quotes too.

And I tried the range operator directly and it works, but my query comes as queryString, so I need it working in queryString.

CodePudding user response:

if you have a date object handy great. If not, something like this (pseudocode/JS):

date = new Date;
date = date.toISOString();

then, here is the query from the docs:

    {
        "$search": {
           "index": "default",
           "range": {
              "path": "anyField",
              "gte": "2000-01-30T20:19:53.123Z",
              "lte": date,
           }
        }
}

CodePudding user response:

According to mongodb engineers, the queryString operators only accept AND and OR. It doesn't accept any other operator like TO, used in range filters.

  • Related