[COMPASS-7278] Investigate changes in SERVER-69836: mongos doesn't raise validation errors but returns empty cursors when the database doesn't exist Created: 28/Sep/23  Updated: 04/Oct/23  Resolved: 04/Oct/23

Status: Closed
Project: Compass
Component/s: None
Affects Version/s: None
Fix Version/s: No version

Type: Investigation Priority: Minor - P4
Reporter: Backlog - Core Eng Program Management Team Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-69836 mongos doesn't raise validation error... Closed
Documentation Changes: 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.



 Comments   
Comment by Jessica Sigafoos [ 04/Oct/23 ]

No work required in the DevTools

Comment by PM Bot [ 28/Sep/23 ]

Fix Version updated for upstream SERVER-69836:
7.2.0-rc0

Generated at Wed Feb 07 22:46:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.