Apply filter only to min elements of two fields

I need to filter the collection by the following condition: the minimum value of two fields in each document must be less than 0.1.

Example:

fdrp_bh_ref fdrp_bh_alt
0.01 1.0
1.0 0.01
0.6 0.8

Expected result:

fdrp_bh_ref fdrp_bh_alt
0.01 1.0
1.0 0.01

This is done very easily in Python:

two_dim = [[0.01, 1.0], [1.0, 0.01], [0.6, 0.8]]
print(list(filter(lambda row: min(row) < 0.1, two_dim)))

[[0.01, 1.0], [1.0, 0.01]]

Is it possible to do it in MongoDB?

The following should work:

{ "$or" : [ { "fdrp_bh_ref" : { "$lt" : 0.1 } } , { "drp_bh_alt" : { "$lt" : 0.1 } } ] }

Untested of course.

In the future, if you could provide your simple documents as JSON strings, we could cut-n-paste them and test.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.