summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMathias Stearn <redbeard0531@gmail.com>2009-11-20 01:57:19 -0500
committerMathias Stearn <redbeard0531@gmail.com>2009-11-20 01:57:52 -0500
commit3e269473da363d680cefd19c0faf94125a0440db (patch)
treee30d8f0a7e2a98728156d563dc75e133dfe4ce19 /tools
parentc7fb263e1a33883515e3f069fac3e5def7988359 (diff)
downloadmongo-3e269473da363d680cefd19c0faf94125a0440db.tar.gz
mongofiles put --replace
Diffstat (limited to 'tools')
-rw-r--r--tools/files.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/tools/files.cpp b/tools/files.cpp
index b35416bd591..e69a0701583 100644
--- a/tools/files.cpp
+++ b/tools/files.cpp
@@ -37,6 +37,7 @@ public:
add_options()
( "local,l", po::value<string>(), "local filename for put|get (default is to use the same name as 'gridfs filename')")
( "type,t", po::value<string>(), "MIME type for put (default is to omit)")
+ ( "replace,r", "Remove other files with same name after PUT")
;
add_hidden_options()
( "command" , po::value<string>() , "command (list|search|put|get)" )
@@ -124,7 +125,20 @@ public:
const string& infile = getParam("local", filename);
const string& type = getParam("type", "");
- cout << "file object: " << g.storeFile(infile, filename, type) << endl;
+ BSONObj file = g.storeFile(infile, filename, type);
+ cout << "added file: " << file << endl;
+
+ if (hasParam("replace")){
+ auto_ptr<DBClientCursor> cursor = conn().query(_db+".fs.files", BSON("filename" << filename << "_id" << NE << file["_id"] ));
+ while (cursor->more()){
+ BSONObj o = cursor->nextSafe();
+ conn().remove(_db+".fs.files", BSON("_id" << o["_id"]));
+ conn().remove(_db+".fs.chunks", BSON("_id" << o["_id"]));
+ cout << "removed file: " << o << endl;
+ }
+
+ }
+
cout << "done!";
return 0;
}