Resolve custom user condition from a collection - mongodb

Viewed 17

The idea was that exercises should only be returned where applicable. All condition properties are stored in the user collection.

As an an example

exercises collection

  title: string,
  conditions?: [
                { property: string, // field from the user collection 
                  operator: string, // (gt, eq, gte, lte, ...)
                  value: string
                }
               ]
  

Each exercise can have one or more conditions.

It could look like this:

      conditions: [
                    { property: 'age',
                      operator: 'gte'
                      value: '18'
                    }
                   ]

Current solution

With my current solution in the backend, I go through the result of mongodb and only return the one where the condition applies or is empty.

The problem

Unfortunately, that's not the best-performing solution.

.

Would that be possible with the aggregation framework?

Unfortunately, that overwhelms my aggregation knowledge.

Open for any solution ideas? :)

best regards

0 Answers
Related