How to write plain match expression in doctrine ODM

60 views Asked by At

I have big pipeline that Im writing now into doctrine ODM, currently with the pipeline Im getting to these kind of documents:

{
"_id":"M-1ea13520-7c30-4482-b5bf-2f8467aa1735",
"chatId":"C-91772cdf-c10b-4faa-9536-98a65554356c",
"publishedAt":{"$date":{"$numberLong":"1696322511000"}},
"lastSeen":{"$date":{"$numberLong":"1696204800000"}}
}

Now Im just trying to make a simple match query that works in plain mongodb and looks like this:

{
    $match:
      {
        $expr: {
          $lt: ["$lastSeen", "$publishedAt"],
        },
      },
  },

This works and now Im simply trying to transcribe this into doctrine ODM like this:

->match()->field('$lastSeen')->lt('$publishedAt')

but I keep getting error: unknown top level operator: $lastSeen. If you have a field name that starts with a '$' symbol, consider using $getField or $setField.

What can I do about this, how do you do this in doctrine ODM?

1

There are 1 answers

0
user2740217 On

Ok managed to do it on my own:

->match()->addAnd(['$expr' => ['$lt' => ['$lastSeen', '$publishedAt']]])