[SERVER-69836] mongos doesn't raise validation errors but returns empty cursors when the database doesn't exist Created: 20/Sep/22  Updated: 29/Oct/23  Resolved: 28/Sep/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Gil Alon Assignee: Colin Stolley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by COMPASS-7278 Investigate changes in SERVER-69836: ... Closed
Documented
Related
related to SERVER-82045 Make $merge inside a $lookup behave t... Backlog
is related to SERVER-63811 mongos returns no results for $docume... Closed
Assigned Teams:
Query Execution
Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

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 Githook User [ 28/Sep/23 ]

Author:

{'name': 'Colin Stolley', 'email': 'colin.stolley@mongodb.com', 'username': 'ccstolley'}

Message: SERVER-69836: mongos doesn't raise validation errors when database does not exist
Branch: master
https://github.com/mongodb/mongo/commit/2e30117034ede2f90767bd03f69cd619d55742b4

Generated at Thu Feb 08 06:14:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.