diff options
author | Bernard Gorman <bernard.gorman@gmail.com> | 2017-12-01 23:04:58 +0000 |
---|---|---|
committer | Bernard Gorman <bernard.gorman@gmail.com> | 2017-12-05 18:48:50 +0000 |
commit | f9c698b67e6e08c05f4667d222a053f8f612d350 (patch) | |
tree | 9be97bf70016848b0da88f04a8d9512015f177e7 /src/mongo/db/commands/run_aggregate.cpp | |
parent | 84b68e8459df1b795fa25eeaee05b76967eb9406 (diff) | |
download | mongo-f9c698b67e6e08c05f4667d222a053f8f612d350.tar.gz |
SERVER-31885 Prohibit $changeStream from running on a non-existent database
Diffstat (limited to 'src/mongo/db/commands/run_aggregate.cpp')
-rw-r--r-- | src/mongo/db/commands/run_aggregate.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index 7c430629d9b..4406c84240e 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -362,9 +362,16 @@ Status runAggregate(OperationContext* opCtx, // of the collection on which $changeStream was invoked, so that we do not end up // resolving the collation on the oplog. invariant(!collatorToUse); - // Change streams can only be created on collections. An error will be raised in - // AutoGetCollection if the given namespace is a view. + // Change streams can only be run against collections; AutoGetCollection will raise an + // error if the given namespace is a view. A change stream may be opened on a namespace + // before the associated collection is created, but only if the database already exists. + // If the $changeStream was sent from mongoS then the database exists at the cluster + // level even if not yet present on this shard, so we allow the $changeStream to run. AutoGetCollection origNssCtx(opCtx, origNss, MODE_IS); + uassert(ErrorCodes::NamespaceNotFound, + str::stream() << "cannot open $changeStream for non-existent database: " + << origNss.db(), + origNssCtx.getDb() || request.isFromMongos()); Collection* origColl = origNssCtx.getCollection(); collatorToUse.emplace(resolveCollator(opCtx, request, origColl)); } |