Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-7278

Investigate changes in SERVER-69836: mongos doesn't raise validation errors but returns empty cursors when the database doesn't exist

    XMLWordPrintableJSON

Details

    • Icon: Investigation Investigation
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • No version
    • None
    • None
    • None
    • Not Needed

    Description

      Original Downstream Change Summary

      mongos will now raise validation errors in the same manner as mongod when aggregations are run against non-existent databases. Previously mongos would return an empty cursor when the database is not found.

      Description of Linked Ticket

      mongos returns an empty cursor with this aggregation when the db does not exist.

      db.aggregate([{$match: {size: "medium"}}, {$documents: [{_id: 1, size: "medium"}, {_id: 2}]}]); 

      This command should return an error since $documents can only be used in the first stage in a pipeline.

      Additionally, mongos will return an empty cursor with this aggregation. This aggregation should also raise an error since $unionWith must be used with a collection.

      db.aggregate([
        {
           $unionWith: { 
               pipeline: [{ $documents: {$map: {input: {$range: [0, 5]}, in : {x: "$$this"}}}}] 
           }       
         }, 
         { $group: {_id: "$x", x: {$first: "$x"}}},
         { $project: {_id: 0}},    
       ])    
       .toArray();    

      Discovered in SERVER-63811.  The empty cursor is being returned by this logic:

          if (executionNsRoutingInfoStatus.isOK()) {
              cm = std::move(executionNsRoutingInfoStatus.getValue());
          } else if (!(hasChangeStream &&
                       executionNsRoutingInfoStatus == ErrorCodes::NamespaceNotFound)) {
              appendEmptyResultSetWithStatus(
                  opCtx, namespaces.requestedNss, executionNsRoutingInfoStatus.getStatus(), result);
              return Status::OK();
          }
      

      However validation checks should have occurred before this logic and returned an error.

      Attachments

        Activity

          People

            Unassigned Unassigned
            backlog-server-pm Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: