summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2016-07-18 11:13:53 -0400
committerJames Wahlin <james.wahlin@10gen.com>2016-07-18 11:16:15 -0400
commit4d826acb5648a78d0af0fefac5abe6fbbe7c854a (patch)
treea6ac4d84d74dc1531add500bc6c3abce3a00df51
parentc970ae123e3f86bc84e8484487a946daa982dc1e (diff)
downloadmongo-4d826acb5648a78d0af0fefac5abe6fbbe7c854a.tar.gz
Revert "SERVER-24506 listCollections support for views"r3.3.10
This reverts commit bfa627513c781c9e61b25dcf993fcd01aaeed0c3.
-rw-r--r--jstests/core/list_collections1.js2
-rw-r--r--jstests/hooks/validate_collections.js11
-rw-r--r--src/mongo/db/commands/list_collections.cpp72
3 files changed, 21 insertions, 64 deletions
diff --git a/jstests/core/list_collections1.js b/jstests/core/list_collections1.js
index b6466ea4a87..9745adc1f90 100644
--- a/jstests/core/list_collections1.js
+++ b/jstests/core/list_collections1.js
@@ -30,8 +30,6 @@
})[0];
assert(collObj);
assert.eq('object', typeof(collObj.options));
- assert.eq('collection', collObj.type, tojson(collObj));
- assert.eq(false, collObj.info.readOnly, tojson(collObj));
//
// Test basic usage with DBCommandCursor.
diff --git a/jstests/hooks/validate_collections.js b/jstests/hooks/validate_collections.js
index 946a0663894..5024460f05a 100644
--- a/jstests/hooks/validate_collections.js
+++ b/jstests/hooks/validate_collections.js
@@ -20,14 +20,9 @@ function validateCollections(db, obj) {
var full = obj.full;
var success = true;
-
- // Don't run validate on view namespaces.
- let listCollectionsRes = db.runCommand({listCollections: 1, filter: {"type": "collection"}});
- assert.commandWorked(listCollectionsRes);
- let collInfo = new DBCommandCursor(db.getMongo(), listCollectionsRes).toArray();
-
- for (var collDocument of collInfo) {
- var coll = db.getCollection(collDocument["name"]);
+ var collNames = db.getCollectionNames();
+ for (var collName of collNames) {
+ var coll = db.getCollection(collName);
var res = coll.validate(full);
if (!res.ok || !res.valid) {
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index 23cd2ff6845..b38e3b07c3d 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -48,8 +48,6 @@
#include "mongo/db/query/find_common.h"
#include "mongo/db/service_context.h"
#include "mongo/db/storage/storage_engine.h"
-#include "mongo/db/storage/storage_options.h"
-#include "mongo/db/views/view_catalog.h"
#include "mongo/stdx/memory.h"
namespace mongo {
@@ -107,56 +105,37 @@ boost::optional<vector<StringData>> _getExactNameMatches(const MatchExpression*
* Does not add any information about the system.namespaces collection, or non-existent collections.
*/
void _addWorkingSetMember(OperationContext* txn,
- const BSONObj& maybe,
+ const Collection* collection,
const MatchExpression* matcher,
WorkingSet* ws,
QueuedDataStage* root) {
- if (matcher && !matcher->matchesBSON(maybe)) {
- return;
- }
-
- WorkingSetID id = ws->allocate();
- WorkingSetMember* member = ws->get(id);
- member->keyData.clear();
- member->recordId = RecordId();
- member->obj = Snapshotted<BSONObj>(SnapshotId(), maybe);
- member->transitionToOwnedObj();
- root->pushBack(id);
-}
-
-BSONObj buildViewBson(const ViewDefinition& view) {
- BSONObjBuilder b;
- b.append("name", view.name().coll());
- b.append("type", "view");
- BSONObj options = BSON("viewOn" << view.viewOn().coll() << "pipeline" << view.pipeline());
- b.append("options", options);
- BSONObj info = BSON("readOnly" << true);
- b.append("info", info);
- return b.obj();
-}
-
-BSONObj buildCollectionBson(OperationContext* txn, const Collection* collection) {
-
if (!collection) {
- return {};
+ return;
}
StringData collectionName = collection->ns().coll();
if (collectionName == "system.namespaces") {
- return {};
+ return;
}
BSONObjBuilder b;
b.append("name", collectionName);
- b.append("type", "collection");
CollectionOptions options = collection->getCatalogEntry()->getCollectionOptions(txn);
b.append("options", options.toBSON());
- BSONObj info = BSON("readOnly" << storageGlobalParams.readOnly);
- b.append("info", info);
+ BSONObj maybe = b.obj();
+ if (matcher && !matcher->matchesBSON(maybe)) {
+ return;
+ }
- return b.obj();
+ WorkingSetID id = ws->allocate();
+ WorkingSetMember* member = ws->get(id);
+ member->keyData.clear();
+ member->recordId = RecordId();
+ member->obj = Snapshotted<BSONObj>(SnapshotId(), maybe);
+ member->transitionToOwnedObj();
+ root->pushBack(id);
}
class CmdListCollections : public Command {
@@ -233,7 +212,7 @@ public:
ScopedTransaction scopedXact(txn, MODE_IS);
AutoGetDb autoDb(txn, dbname, MODE_S);
- Database* db = autoDb.getDb();
+ const Database* db = autoDb.getDb();
auto ws = make_unique<WorkingSet>();
auto root = make_unique<QueuedDataStage>(txn, ws.get());
@@ -242,27 +221,12 @@ public:
if (auto collNames = _getExactNameMatches(matcher.get())) {
for (auto&& collName : *collNames) {
auto nss = NamespaceString(db->name(), collName);
- Collection* collection = db->getCollection(nss);
- BSONObj collBson = buildCollectionBson(txn, collection);
- if (!collBson.isEmpty()) {
- _addWorkingSetMember(txn, collBson, matcher.get(), ws.get(), root.get());
- }
+ _addWorkingSetMember(
+ txn, db->getCollection(nss), matcher.get(), ws.get(), root.get());
}
} else {
for (auto&& collection : *db) {
- BSONObj collBson = buildCollectionBson(txn, collection);
- if (!collBson.isEmpty()) {
- _addWorkingSetMember(txn, collBson, matcher.get(), ws.get(), root.get());
- }
- }
- }
- auto viewCatalog = db->getViewCatalog();
- if (viewCatalog) {
- for (auto& view : *viewCatalog) {
- BSONObj viewBson = buildViewBson(*(view.second.get()));
- if (!viewBson.isEmpty()) {
- _addWorkingSetMember(txn, viewBson, matcher.get(), ws.get(), root.get());
- }
+ _addWorkingSetMember(txn, collection, matcher.get(), ws.get(), root.get());
}
}
}