A mongos will return an empty result set on any pipeline with a $documents stage like this one:
db.aggregate([{$documents: [{_id: 1}, {_id: 2}]}]);
I believe this is due to this logic:
// If the routing table is valid, we obtain a reference to it. If the table is not valid, then
// either the database does not exist, or there are no shards in the cluster. In the latter
// case, we always return an empty cursor. In the former case, if the requested aggregation is a
// $changeStream, we allow the operation to continue so that stream cursors can be established
// on the given namespace before the database or collection is actually created. If the database
// does not exist and this is not a $changeStream, then we return an empty cursor.
boost::optional<ChunkManager> cm;
auto executionNsRoutingInfoStatus =
sharded_agg_helpers::getExecutionNsRoutingInfo(opCtx, namespaces.executionNss);
if (!executionNsRoutingInfoStatus.isOK()) {
if (liteParsedPipeline.startsWithCollStats()) {
uassertStatusOKWithContext(executionNsRoutingInfoStatus,
"Unable to retrieve information for $collStats stage");
}
}
if (executionNsRoutingInfoStatus.isOK()) {
cm = std::move(executionNsRoutingInfoStatus.getValue());
} else if (!(hasChangeStream &&
executionNsRoutingInfoStatus == ErrorCodes::NamespaceNotFound)) {
appendEmptyResultSetWithStatus(
opCtx, namespaces.requestedNss, executionNsRoutingInfoStatus.getStatus(), result);
return Status::OK();
}
This is a behavioral difference from a replica set, and can make writing tests annoying (discovered in SERVER-63793).
The new, requested behavior is to allow the operation to continue even if the db doesn't exist for $documents. Similar to how $changeStreams is handled, it may be the case that special support/case handling will have to be added to support $documents if current agg implementation isn't prepared to handle the db not existing.
- is duplicated by
-
SERVER-71728 $documents not working on sharded cluster in 6.1
-
- Closed
-
- is related to
-
SERVER-63793 Add test demonstrating behavior of $setWindowField's 'output' parameter
-
- Closed
-
- related to
-
SERVER-69836 mongos doesn't raise validation errors but returns empty cursors when the database doesn't exist
-
- Closed
-
-
SERVER-70176 $documents sharding tests runs on versions before 5.1
-
- Closed
-