summaryrefslogtreecommitdiff
path: root/db/dbhelpers.cpp
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-05-11 10:46:54 -0400
committerAaron <aaron@10gen.com>2009-05-11 10:46:54 -0400
commit5a0f2e5501b25188ff5af5a511f340c1a601c847 (patch)
treeb9ccb0848a4a07b18dc3cd409acd4c8cd71959c1 /db/dbhelpers.cpp
parent169f69aceea03f7b639426bc7a3be0b8e18ad80e (diff)
downloadmongo-5a0f2e5501b25188ff5af5a511f340c1a601c847.tar.gz
enhance DbSet
Diffstat (limited to 'db/dbhelpers.cpp')
-rw-r--r--db/dbhelpers.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp
index 7d0b69e7716..3941dd591c9 100644
--- a/db/dbhelpers.cpp
+++ b/db/dbhelpers.cpp
@@ -143,18 +143,37 @@ namespace mongo {
deleteObjects(ns, BSONObj(), false);
}
- void DbSet::reset() {
+ DbSet::~DbSet() {
+ if ( name_.empty() )
+ return;
+ try {
+ DBContext c( name_.c_str() );
+ if ( nsdetails( name_.c_str() ) ) {
+ string errmsg;
+ BSONObjBuilder result;
+ dropCollection( name_, errmsg, result );
+ }
+ } catch ( ... ) {
+ problem() << "exception cleaning up DbSet" << endl;
+ }
+ }
+
+ void DbSet::reset( const string &name, const BSONObj &key ) {
+ if ( !name.empty() )
+ name_ = name;
+ if ( !key.isEmpty() )
+ key_ = key.getOwned();
DBContext c( name_.c_str() );
if ( nsdetails( name_.c_str() ) ) {
Helpers::emptyCollection( name_.c_str() );
} else {
string err;
- massert( err, userCreateNS( name_.c_str(), BSONObj(), err, false ) );
+ massert( err, userCreateNS( name_.c_str(), fromjson( "{autoIndexId:false}" ), err, false ) );
}
Helpers::ensureIndex( name_.c_str(), key_, true, "setIdx" );
}
- bool DbSet::get( const BSONObj &obj ) {
+ bool DbSet::get( const BSONObj &obj ) const {
DBContext c( name_.c_str() );
BSONObj temp;
return Helpers::findOne( name_.c_str(), obj, temp, true );