117 namespace mongotype {
122 const string COPYRIGHT(
"Copyright (c) 2013 by Mark Deazley");
124 "Free Software Foundation’s GNU AGPL v3.0.\n"
125 "This program is free software: you can redistribute it and/or modify\n"
126 "it under the terms of the GNU Affero General Public License as\n"
127 "published by the Free Software Foundation, either version 3 of the\n"
128 "License, or (at your option) any later version.\n"
130 "This program is distributed in the hope that it will be useful,\n"
131 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
132 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
133 "GNU Affero General Public License for more details.\n"
135 "You should have received a copy of the GNU Affero General Public License\n"
136 "along with this program. If not, see http://www.gnu.org/licenses/ .\n");
141 DBClientConnection c;
142 string hostPort(params.
getHost());
143 if (hostPort.find(
':') == string::npos) {
145 hostPort += to_string(params.
getPort());
155 << documentCount <<
" }\n";
163 unique_ptr<DBClientCursor> cursor = c.query(params.
getDbCollection(), BSONObj());
165 unique_ptr<IBSONRenderer> renderer;
171 renderer = unique_ptr<IBSONRenderer>(
new BSONObjectTypeDump(params, docPrefixString));
175 renderer = unique_ptr<IBSONRenderer>(
new JSONDump(params,
" "));
178 throw std::logic_error(
"ISE: Undefined STYLE!");
183 renderer->
begin(NULL);
184 int documentIndex = 0;
185 while (cursor->more()) {
186 const BSONObj& o = cursor->next();
187 renderer->
render(o, documentIndex++, documentCount);
191 throw std::logic_error(
"ISE: Undefined renderer!");
201 int main(
int argc,
char* argv[]) {
204 params.
parse(argc, argv);
206 }
catch (
const mongo::DBException &e) {
207 cerr <<
"mongotype MongoDB Error: \"" << e.what() <<
"\"" << endl;
209 }
catch (std::logic_error &e) {
210 cerr <<
"mongotype Generic Error: \"" << e.what() <<
"\"" << endl;