summaryrefslogtreecommitdiff
path: root/tools/export.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-10-09 22:11:15 -0400
committerEliot Horowitz <eliot@10gen.com>2009-10-09 22:11:15 -0400
commit8a6dfdc9e967dca275720391dfa297087d4337c0 (patch)
tree5086a873802b0f37b9ed3a4c20257a666a3219f3 /tools/export.cpp
parent6e67c98509d80d88859a23548205d09a6d7d9b4a (diff)
downloadmongo-8a6dfdc9e967dca275720391dfa297087d4337c0.tar.gz
cleaning tool debugging/tests
Diffstat (limited to 'tools/export.cpp')
-rw-r--r--tools/export.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/tools/export.cpp b/tools/export.cpp
index f142cefecb4..16b1cd8baa3 100644
--- a/tools/export.cpp
+++ b/tools/export.cpp
@@ -47,8 +47,21 @@ public:
const bool csv = hasParam( "csv" );
ostream *outPtr = &cout;
string outfile = getParam( "out" );
- if ( hasParam( "out" ) )
- outPtr = new ofstream( outfile.c_str() );
+ auto_ptr<ofstream> fileStream;
+ if ( hasParam( "out" ) ){
+ size_t idx = outfile.rfind( "/" );
+ if ( idx != string::npos ){
+ string dir = outfile.substr( 0 , idx + 1 );
+ create_directories( dir );
+ }
+ ofstream * s = new ofstream( outfile.c_str() , ios_base::out | ios_base::binary );
+ fileStream.reset( s );
+ outPtr = s;
+ if ( ! s->good() ){
+ cerr << "couldn't open [" << outfile << "]" << endl;
+ return -1;
+ }
+ }
ostream &out = *outPtr;
BSONObj * fieldsToReturn = 0;
@@ -85,8 +98,10 @@ public:
}
out << endl;
}
-
+
+ long long num = 0;
while ( cursor->more() ) {
+ num++;
BSONObj obj = cursor->next();
if ( csv ){
for ( vector<string>::iterator i=_fields.begin(); i != _fields.end(); i++ ){
@@ -104,6 +119,8 @@ public:
}
}
+
+ cout << "exported " << num << " records" << endl;
return 0;
}