--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/5f547dcd-9cd7-439d-b612-1a02ebf73662%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d13acf99-43c1-4b7f-9f45-73b133dead5a%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/b7e79313-2a88-42e1-a5e0-5523d6959ca6%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d34b3187-3a5a-49cd-8a90-f3100150bb2c%40googlegroups.com.
Hi Mick,
You can un-cap a capped collection with the following steps:
the copyDatabase works, but the newly created database still has the capped = True.
The capped
status is part of the collection options. Therefore, copying the whole database will not remove the capped
option of a collection.
Below is a C++ code example using the current MongoDB C++ driver that executes the steps listed above:
#include "mongo/client/dbclient.h"
int main() {
/* Initialize Driver */
mongo::Status status = mongo::client::initialize();
if (!status.isOK()){
std::cout<< "Failed to initialize driver." << std::endl;
return EXIT_FAILURE;
}
/* Establish db connection */
mongo::DBClientConnection c;
try {
c.connect("localhost");
} catch( const mongo::DBException &e ) {
std::cout << "caught " << e.what() << std::endl;
}
/* The database name is 'capped' and the capped collection name is 'test',
using a temporary collection in the same database with a name 'temp'.
*/
const std::string CAPPED_COLL = "capped.test";
const std::string UNCAPPED_COLL = "capped.temp";
/* Copy collection from capped to uncapped collection */
std::auto_ptr<mongo::DBClientCursor> cursor = c.query(CAPPED_COLL, mongo::BSONObj());
while(cursor->more()){
mongo::BSONObj p = cursor->next();
c.insert(UNCAPPED_COLL, p);
}
/* Drop capped collection, and rename uncapped to capped collection */
mongo::BSONObj result;
c.runCommand("admin",
BSON("renameCollection"<<UNCAPPED_COLL
<<"to"<<CAPPED_COLL
<<"dropTarget"<<true),
result);
std::cout<< "Completed" <<std::endl;
return EXIT_SUCCESS;
}
Kind Regards,
Wan.