-
Type: Investigation
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
-
Not Needed
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.
- depends on
-
SERVER-69836 mongos doesn't raise validation errors but returns empty cursors when the database doesn't exist
- Closed