Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-35230

Add ability to subquery on an array with similar syntax as querying documents

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Querying
    • None
    • Query Optimization

    Description

      Finding the right way to construct a find against elements in an array field can get rather tricky, and the rules become very opaque for those with less experience with MongoDB. 

       

      What I suggest is the ability to essentially nest a subquery into your find/$match, which would treat an array as the new collection. The results of the subquery would replace the array for the rest of the parent find's execution (including what is returned as final result).

      Example:

      db.collection.find({
       firstname: 'Jones',
       lastname: 'Sally',
       addresses: {$arrayFind: {
         state:'TX',
         $sort:{zip:1},
       }}
      )
      

       

      We already have pieces of this in filter, elemmatch, etc, but this feels like it would be a much cleaner interface overall, and allow for some constructs we're still missing. 

       

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            rod.adams@mongodb.com Rod Adams
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

              Created:
              Updated: