summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/mr_common.cpp
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@10gen.com>2012-11-14 22:17:22 -0500
committerSpencer T Brody <spencer@10gen.com>2012-11-29 16:55:59 -0500
commit965ad9961052a7dab133ca86e65c0aa210b3a71e (patch)
tree0409e3ced5e0841b582a84cfe2ba358786607a63 /src/mongo/db/commands/mr_common.cpp
parente013f359da0fe8573f2b33f007fc5bdb2529d458 (diff)
downloadmongo-965ad9961052a7dab133ca86e65c0aa210b3a71e.tar.gz
Move MapReduce option parsing somewhere it can be accessed by mongos and mongod SERVER-7122
Diffstat (limited to 'src/mongo/db/commands/mr_common.cpp')
-rw-r--r--src/mongo/db/commands/mr_common.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/mongo/db/commands/mr_common.cpp b/src/mongo/db/commands/mr_common.cpp
new file mode 100644
index 00000000000..215084582d9
--- /dev/null
+++ b/src/mongo/db/commands/mr_common.cpp
@@ -0,0 +1,89 @@
+/**
+ * Copyright (C) 2012 10gen Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mongo/db/commands/mr.h"
+
+#include <string>
+
+#include "mongo/db/jsobj.h"
+#include "mongo/util/mongoutils/str.h"
+
+namespace mongo {
+
+ namespace mr {
+ Config::OutputOptions Config::parseOutputOptions(const std::string& dbname,
+ const BSONObj& cmdObj) {
+ Config::OutputOptions outputOptions;
+
+ outputOptions.outNonAtomic = false;
+ if (cmdObj["out"].type() == String) {
+ outputOptions.collectionName = cmdObj["out"].String();
+ outputOptions.outType = REPLACE;
+ }
+ else if (cmdObj["out"].type() == Object) {
+ BSONObj o = cmdObj["out"].embeddedObject();
+
+ BSONElement e = o.firstElement();
+ string t = e.fieldName();
+
+ if (t == "normal" || t == "replace") {
+ outputOptions.outType = REPLACE;
+ outputOptions.collectionName = e.String();
+ }
+ else if (t == "merge") {
+ outputOptions.outType = MERGE;
+ outputOptions.collectionName = e.String();
+ }
+ else if (t == "reduce") {
+ outputOptions.outType = REDUCE;
+ outputOptions.collectionName = e.String();
+ }
+ else if (t == "inline") {
+ outputOptions.outType = INMEMORY;
+ }
+ else {
+ uasserted(13522,
+ mongoutils::str::stream() << "unknown out specifier [" << t << "]");
+ }
+
+ if (o.hasElement("db")) {
+ outputOptions.outDB = o["db"].String();
+ }
+
+ if (o.hasElement("nonAtomic")) {
+ outputOptions.outNonAtomic = o["nonAtomic"].Bool();
+ if (outputOptions.outNonAtomic)
+ uassert(15895,
+ "nonAtomic option cannot be used with this output type",
+ (outputOptions.outType == REDUCE ||
+ outputOptions.outType == MERGE));
+ }
+ }
+ else {
+ uasserted(13606 , "'out' has to be a string or an object");
+ }
+
+ if (outputOptions.outType != INMEMORY) {
+ outputOptions.finalNamespace = mongoutils::str::stream()
+ << (outputOptions.outDB.empty() ? dbname : outputOptions.outDB)
+ << "." << outputOptions.collectionName;
+ }
+
+ return outputOptions;
+ }
+ }
+
+}