Mongodb query to select less than and equal based on custom comparator -
i using mongodb database , need run less , equal filter based on custom comparator. following more details.
"profile" collection having "level" field string
{"name":"test1", "level":"intermediate"}
following value of level , corresponding weight
- novice
- intermediate
- experienced
- advance
i want write query below should return profile collection level less , equal "experienced" (i.e. includes result "novice", "intermediate" , "experienced"
db.profile.find( { level: { $lte: "experienced" } } )
i understand, need provide custom comparator. how can do?
you can't use custom comparators in mongodb query. ones available are: $eq
, $gt
, $gte
, $lt
, $lte
, $ne
, $in
, $nin
.
you can, however, use $in
want:
db.profile.find( { level: { $in: [ "experienced", "intermediate ", "novice" ] } } );
Comments
Post a Comment