diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.cpp | 60 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.h | 9 | ||||
-rw-r--r-- | src/mongo/db/commands/mr_common.cpp | 89 |
4 files changed, 98 insertions, 61 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index fba3c8c56d8..97e5d0dd71b 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -202,6 +202,7 @@ env.StaticLibrary("coredb", [ "db/commands/find_and_modify_common.cpp", "db/commands/hashcmd.cpp", "db/commands/isself.cpp", + "db/commands/mr_common.cpp", "db/commands/server_status.cpp", "db/commands/parameters.cpp", "db/pipeline/pipeline.cpp", diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index f01133030e4..ea8c21a68d1 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -216,66 +216,6 @@ namespace mongo { _reduce( x , key , endSizeEstimate ); } - Config::OutputOptions Config::parseOutputOptions(const 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 , 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 = str::stream() << - (outputOptions.outDB.empty() ? dbname : outputOptions.outDB) << - "." << outputOptions.collectionName; - } - - return outputOptions; - } - Config::Config( const string& _dbname , const BSONObj& cmdObj ) { dbname = _dbname; diff --git a/src/mongo/db/commands/mr.h b/src/mongo/db/commands/mr.h index 4ad11765947..c05979e79bf 100644 --- a/src/mongo/db/commands/mr.h +++ b/src/mongo/db/commands/mr.h @@ -18,7 +18,14 @@ #pragma once -#include "mongo/pch.h" +#include <boost/scoped_ptr.hpp> +#include <string> +#include <vector> + +#include "mongo/db/curop.h" +#include "mongo/db/instance.h" +#include "mongo/db/jsobj.h" +#include "mongo/scripting/engine.h" namespace mongo { 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; + } + } + +} |