Skip to content

How to return a count of 0 from the pipeline #22

@davesykeselateral

Description

@davesykeselateral

Is your feature request related to a problem? Please describe

I am attempting to produce a metric that is the number of items, and that count can be 0. In this case I am trying to get the count of stuck orders in the system.

Pipeline:

[
  {"$match": {"status": "STUCK"}},
  {"$count": {"total"}
]

This works great when there is at least 1 stuck order, however, if there are none, then there are no documents going through the pipeline, so the $count step does not do anything, and 0 records are returned, which means the mongodb-query-exporter does not see this as a valid metric and does not report it. From looking around, the recommended approach is to see if 0 records are returned from a $count step in a pipeline, interpret this as 0 records. I do not see a way of doing this in mongodb-query-exporter currently.

So far I have managed to come up with adding an item into the pipeline just before the count, then subtracting 1 from it at the end, but not very nice!

Describe the solution you'd like

A way of returning a 0 count

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions