summaryrefslogtreecommitdiff
path: root/db/dbhelpers.cpp
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-05-06 20:24:01 -0400
committerAaron <aaron@10gen.com>2009-05-06 20:24:01 -0400
commit898b1feb1402a4bd915fed73a1d8abe235a8e36e (patch)
tree5c69bdcfc3a506928d58b76a4bf55d023a394397 /db/dbhelpers.cpp
parent47ebf4cf08a1a3d9a4018eba8a5fc57d2c428ab2 (diff)
downloadmongo-898b1feb1402a4bd915fed73a1d8abe235a8e36e.tar.gz
extracted DbSet
Diffstat (limited to 'db/dbhelpers.cpp')
-rw-r--r--db/dbhelpers.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp
index e46946c1c49..7d0b69e7716 100644
--- a/db/dbhelpers.cpp
+++ b/db/dbhelpers.cpp
@@ -143,4 +143,35 @@ namespace mongo {
deleteObjects(ns, BSONObj(), false);
}
+ void DbSet::reset() {
+ 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 ) );
+ }
+ Helpers::ensureIndex( name_.c_str(), key_, true, "setIdx" );
+ }
+
+ bool DbSet::get( const BSONObj &obj ) {
+ DBContext c( name_.c_str() );
+ BSONObj temp;
+ return Helpers::findOne( name_.c_str(), obj, temp, true );
+ }
+
+ void DbSet::set( const BSONObj &obj, bool val ) {
+ DBContext c( name_.c_str() );
+ if ( val ) {
+ try {
+ BSONObj k = obj;
+ theDataFileMgr.insert( name_.c_str(), k );
+ } catch ( DBException& ) {
+ // dup key - already in set
+ }
+ } else {
+ deleteObjects( name_.c_str(), obj, true, false, false );
+ }
+ }
+
} // namespace mongo