Having problems with php, atlas search compound and date ranges

Hello people, I just started using mongo few days ago and I have a problem that I can’t find a solution

The steps that I followed are:

  1. I created my pipeline using MongoDB Compass first and it worked!, here is my pipeline:
[
  {
    $search: {
      index: "search_queryString",
      compound: {
        must: [
          {
            text: {
              query: "123",
              path: "organization_id",
            },
          },
          {
            range: {
              path: "created_at",
              gte: ISODate('2024-01-01T00:00:00Z'),
              lte: ISODate('2024-06-01T00:00:00Z'),
            },
          },
        ],
      },
      sort: { created_at: -1 },
    },
  }
]
  1. I created my code using php but when I use php I get some weird error, here is my pipeline generated with php:
[
  {
    $search: {
      index: "search_queryString",
      compound: {
        must: [
          {
            text: {
              query: "123",
              path: "organization_id",
            },
          },
          {
            range: {
              path: "created_at",
              gte: {
                $date: {
                  $numberLong: "1720249200",
                },
              },
              lte: {
                $date: {
                  $numberLong: "1723100399",
                },
              },
            },
          },
        ],
      },
      sort: { created_at: -1 },
    },
  }
]

as you see the only one thing that’s replaced is the ISODate, it’s getting replaced with a BSON object and this is normal of course

but the problem is that this query is not working, for some reason when I try to run this pipeline the PlanExecutor returns me an error because is asking for a type, here is the error

Looks like the error message didn’t get included. What was the error? Also, can you share your index configuration JSON as well? Thanks!

I found an interesting bug @Erik_Hatcher

If I use this query in the Search Tester (Inside of my search & vector index) it works

[{"$search":{"index":"userDocumentsIndex","range":{"path":"created_at","gte":{"$date":{"$numberLong":"1262304000000"}},"lt":{"$date":{"$numberLong":"1893456000000"}}},"sort":{"created_at":-1}}}]

but for some reason if I just click on “Format” button in your platform it doesn’t work and returns the same error

"range.lt.type" is required
"compound.must[1].range.lte.type" is required

here is the error

and this is my Index config JSON:

{
  "mappings": {
    "dynamic": true,
    "fields": {
      "created_at": {
        "type": "date"
      },
      "name": {
        "type": "string"
      },
      "organization_id": {
        "type": "string"
      }
    }
  }
}

Try this in the Atlas aggregation tool, or via Compass - does the error occur there?

I am getting the same error, I just created another collection and I am trying to filter by date

this is my aggregation: running on MongoDB Compass

[
  {
    $search: {
      index: "serviceLogsIndex",
      compound: {
        must: [
          {
            text: {
              query: "5bd09a7c08228b112371bdc3",
              path: "organization_id",
            },
          },
          {
            range: {
              path: "created_at",
              gt: {
                $date: {
                  $numberLong: "1722470400",
                },
              },
              lt: {
                $date: {
                  $numberLong: "1724716799",
                },
              },
            },
          },
        ],
      },
    },
  },
  {
    $group: {
      _id: "$service",
      services: { $count: {} },
    },
  },
]

and this is my atlas index json

{
  "mappings": {
    "dynamic": true,
    "fields": {
      "created_at": {
        "type": "date"
      },
      "organization_id": {
        "type": "string"
      },
      "service": {
        "type": "string"
      }
    }
  }
}

I am using mongodb version 5