Skip to content

Commit c242324

Browse files
committed
CXX-186 Use StringData, improve comments, take refs
1 parent 1e974de commit c242324

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

src/mongo/client/dbclient.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,13 @@ namespace mongo {
792792
}
793793

794794
void DBClientWithCommands::group(
795-
const std::string& ns,
796-
const std::string& jsreduce,
795+
const StringData& ns,
796+
const StringData& jsreduce,
797797
std::vector<BSONObj>* output,
798798
const BSONObj& initial,
799799
const BSONObj& cond,
800800
const BSONObj& key,
801-
const std::string& finalize
801+
const StringData& finalize
802802
) {
803803
BSONObjBuilder groupObjBuilder;
804804
_buildGroupObj(ns, jsreduce, initial, cond, finalize, &groupObjBuilder);
@@ -810,13 +810,13 @@ namespace mongo {
810810
}
811811

812812
void DBClientWithCommands::groupWithKeyFunction(
813-
const std::string& ns,
814-
const std::string& jsreduce,
813+
const StringData& ns,
814+
const StringData& jsreduce,
815815
std::vector<BSONObj>* output,
816816
const BSONObj& initial,
817817
const BSONObj& cond,
818-
const std::string& jskey,
819-
const std::string& finalize
818+
const StringData& jskey,
819+
const StringData& finalize
820820
) {
821821
BSONObjBuilder groupBuilder;
822822
_buildGroupObj(ns, jsreduce, initial, cond, finalize, &groupBuilder);
@@ -828,14 +828,14 @@ namespace mongo {
828828
}
829829

830830
void DBClientWithCommands::_buildGroupObj(
831-
const std::string& ns,
832-
const std::string& jsreduce,
831+
const StringData& ns,
832+
const StringData& jsreduce,
833833
const BSONObj& initial,
834834
const BSONObj& cond,
835-
const std::string& finalize,
835+
const StringData& finalize,
836836
BSONObjBuilder* groupObj
837837
) {
838-
groupObj->append("ns", nsGetCollection(ns));
838+
groupObj->append("ns", nsGetCollection(ns.toString()));
839839
groupObj->appendCode("$reduce", jsreduce);
840840
groupObj->append("initial", initial);
841841

@@ -845,12 +845,12 @@ namespace mongo {
845845
groupObj->append("finalize", finalize);
846846
}
847847

848-
void DBClientWithCommands::_runGroup(const std::string ns, const BSONObj& group, std::vector<BSONObj>* output) {
848+
void DBClientWithCommands::_runGroup(const StringData& ns, const BSONObj& group, std::vector<BSONObj>* output) {
849849
BSONObjBuilder commandBuilder;
850850
commandBuilder.append("group", group);
851851

852852
BSONObj result;
853-
bool ok = runCommand(nsGetDB(ns), commandBuilder.obj(), result);
853+
bool ok = runCommand(nsGetDB(ns.toString()), commandBuilder.obj(), result);
854854

855855
if (!ok)
856856
throw OperationException(result);

src/mongo/client/dbclientinterface.h

+19-16
Original file line numberDiff line numberDiff line change
@@ -822,10 +822,13 @@ namespace mongo {
822822
BSONObj mapreduce(const std::string &ns, const std::string &jsmapf, const std::string &jsreducef, BSONObj query = BSONObj(), MROutput output = MRInline);
823823

824824
/**
825-
* Groups documents in a collection by the specified keys and performs simple aggregation
825+
* Groups documents in a collection by the specified key and performs simple aggregation
826826
* functions such as computing counts and sums.
827827
*
828-
* See: http://docs.mongodb.org/manual/reference/method/db.collection.group
828+
* @note WARNING: Use of the group command is strongly discouraged, it is much better to use
829+
* the aggregation framework to acheive similar functionality.
830+
*
831+
* @see http://docs.mongodb.org/manual/reference/method/db.collection.group
829832
*
830833
* @param ns The namespace to group
831834
* @param key The field or fields to group specified as a projection document: { field: 1 }
@@ -839,30 +842,30 @@ namespace mongo {
839842
* returning the final values in the output vector.
840843
*/
841844
void group(
842-
const std::string& ns,
843-
const std::string& jsreduce,
845+
const StringData& ns,
846+
const StringData& jsreduce,
844847
std::vector<BSONObj>* output,
845848
const BSONObj& initial = BSONObj(),
846849
const BSONObj& cond = BSONObj(),
847850
const BSONObj& key = BSONObj(),
848-
const std::string& finalize = ""
851+
const StringData& finalize = ""
849852
);
850853

851854
/**
852-
* Does the same thing as group but accepts a key function that can be used to create the
853-
* object representing the key. This allows for grouping on calculated fields rather than
854-
* existing fields alone.
855+
* Does the same thing as 'group' but accepts a key function, 'jskey', that is used to
856+
* create an object representing the key. This allows for grouping on calculated fields
857+
* rather on existing fields alone.
855858
*
856859
* @see DBClientWithCommands::group
857860
*/
858861
void groupWithKeyFunction(
859-
const std::string& ns,
860-
const std::string& jsreduce,
862+
const StringData& ns,
863+
const StringData& jsreduce,
861864
std::vector<BSONObj>* output,
862865
const BSONObj& initial = BSONObj(),
863866
const BSONObj& cond = BSONObj(),
864-
const std::string& jskey = "",
865-
const std::string& finalize = ""
867+
const StringData& jskey = "",
868+
const StringData& finalize = ""
866869
);
867870

868871
/** Run javascript code on the database server.
@@ -1058,15 +1061,15 @@ namespace mongo {
10581061
bool _haveCachedAvailableOptions;
10591062

10601063
void _buildGroupObj(
1061-
const std::string& ns,
1062-
const std::string& jsreduce,
1064+
const StringData& ns,
1065+
const StringData& jsreduce,
10631066
const BSONObj& initial,
10641067
const BSONObj& cond,
1065-
const std::string& finalize,
1068+
const StringData& finalize,
10661069
BSONObjBuilder* groupObj
10671070
);
10681071

1069-
void _runGroup(const std::string ns, const BSONObj& group, std::vector<BSONObj>* output);
1072+
void _runGroup(const StringData& ns, const BSONObj& group, std::vector<BSONObj>* output);
10701073
};
10711074

10721075
class DBClientWriter;

0 commit comments

Comments
 (0)