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

mongos doesn't raise validation errors but returns empty cursors when the database doesn't exist

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Minor Change
    • ALL

      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.

            Assignee:
            colin.stolley@mongodb.com Colin Stolley
            Reporter:
            gil.alon@mongodb.com Gil Alon
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: