mongodb - query documents by value of field name mongodb - query documents by value of field name mongoose mongoose

mongodb - query documents by value of field name


Since your keys are unknown you have to convert them to some key value pair using $objectToArray aggregation and then can easily $match with it

db.collection.aggregate([  { "$match": { "points.date[number]": { "$exists": true }}},  { "$addFields": {    "match": {      "$objectToArray": "$points.date"    }  }},  { "$match": { "match.k": { "$lt": "7" }}},  { "$project": { "match": 0 }}])