summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-05-26 15:24:06 -0400
committerEliot Horowitz <eliot@10gen.com>2010-05-26 15:24:06 -0400
commit2ccc219102424eddc6cadf99b13e928e227bdd78 (patch)
tree7fc4ecd675bcc18156ec5477dddfe7263b345456
parent3ffcb16346d34b614c8ffccf869efb2ce37f2a4b (diff)
downloadmongo-2ccc219102424eddc6cadf99b13e928e227bdd78.tar.gz
can filter in mongorestore
-rw-r--r--tools/restore.cpp17
-rw-r--r--util/text.h2
2 files changed, 17 insertions, 2 deletions
diff --git a/tools/restore.cpp b/tools/restore.cpp
index 13fde263025..1df06f1b358 100644
--- a/tools/restore.cpp
+++ b/tools/restore.cpp
@@ -34,11 +34,13 @@ public:
bool _drop;
bool _objcheck;
+ auto_ptr<Matcher> _matcher;
Restore() : Tool( "restore" , true , "" , "" ) , _drop(false),_objcheck(false){
add_options()
("drop" , "drop each collection before import" )
("objcheck" , "validate object before inserting" )
+ ("filter" , po::value<string>() , "filter to apply before inserting" )
;
add_hidden_options()
("dir", po::value<string>()->default_value("dump"), "directory to restore from")
@@ -55,6 +57,9 @@ public:
path root = getParam("dir");
_drop = hasParam( "drop" );
_objcheck = hasParam( "objcheck" );
+
+ if ( hasParam( "filter" ) )
+ _matcher.reset( new Matcher( fromjson( getParam( "filter" ) ) ) );
/* If _db is not "" then the user specified a db name to restore as.
*
@@ -155,6 +160,7 @@ public:
long long read = 0;
long long num = 0;
+ long long inserted = 0;
const int BUF_SIZE = 1024 * 1024 * 5;
boost::scoped_array<char> buf_holder(new char[BUF_SIZE]);
@@ -189,7 +195,11 @@ public:
cerr << "\t " << e << endl;
}
}
- conn().insert( ns.c_str() , o );
+
+ if ( _matcher.get() == 0 || _matcher->matches( o ) ){
+ conn().insert( ns.c_str() , o );
+ inserted++;
+ }
read += o.objsize();
num++;
@@ -198,7 +208,10 @@ public:
}
uassert( 10265 , "counts don't match" , m.done() == fileLength );
- out() << "\t " << m.hits() << " objects" << endl;
+ out() << "\t " << m.hits() << " objects found" << endl;
+ if ( _matcher.get() )
+ out() << "\t " << inserted << " objects inserted" << endl;
+
}
};
diff --git a/util/text.h b/util/text.h
index ba7977dfee5..ef3286bc398 100644
--- a/util/text.h
+++ b/util/text.h
@@ -19,6 +19,8 @@ namespace mongo {
if ( foo ){
string s( _big , foo - _big );
_big = foo + 1;
+ while ( *_big && strstr( _big , _splitter ) == _big )
+ _big++;
return s;
}