0

I try to make big aggregation request in compass. I need to filter data by comparison of ObjectIds

{
  _id: ObjectId("5fcc15d567184993fdfd8a24")
  organizationId: ObjectId("5dc3b48f8f69a100022ab8d8")
  relatedObject: {
    organizationId: ObjectId("5dc3b48f8f69a100022ab8d8")
    ...
  }
}

I need to get collections where organizationId = relatedObject.organizationId. Simple

$match {
  organizationId: { $eq: "$order_history_items.organizationId" }
}

doesn't work and response nothing. I suppose because of ObjectIds comparison. What should I do without toHexString() or similar stuff which isn't available in compass?

Nikita Polevoy
  • 319
  • 5
  • 17
  • 1
    use [$expr](https://docs.mongodb.com/manual/reference/operator/query/expr/) operator to match internal fields. – turivishal Jul 24 '21 at 17:35

1 Answers1

0

answer:

{
  $expr: { $eq: ["$organizationId", "$order_history_items.organizationId"]}
}
Nikita Polevoy
  • 319
  • 5
  • 17