diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-12-02 16:36:32 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-12-02 16:36:32 -0500 |
commit | 95c080d71959ab9091f13af7b30740aab6b9fd1a (patch) | |
tree | f3fa3bd121637158ceff5c07c9219a78f41a2f35 | |
parent | 04c6bf7241c9603b1cbafa045320a16b0536c150 (diff) | |
download | mongo-95c080d71959ab9091f13af7b30740aab6b9fd1a.tar.gz |
Model::remove()
-rw-r--r-- | client/model.cpp | 22 | ||||
-rw-r--r-- | client/model.h | 3 |
2 files changed, 21 insertions, 4 deletions
diff --git a/client/model.cpp b/client/model.cpp index 55aa51c54ee..2b076ddbc50 100644 --- a/client/model.cpp +++ b/client/model.cpp @@ -35,7 +35,23 @@ namespace mongo { return true; } - void Model::save( bool check ){ + void Model::remove( bool safe ){ + uassert( "_id isn't set - needed for remove()" , _id["_id"].type() ); + + ScopedDbConnection conn( modelServer() ); + conn->remove( getNS() , _id ); + + string errmsg = ""; + if ( safe ) + errmsg = conn->getLastError(); + + conn.done(); + + if ( safe && errmsg.size() ) + throw UserException( (string)"error on Model::remove: " + errmsg ); + } + + void Model::save( bool safe ){ ScopedDbConnection conn( modelServer() ); BSONObjBuilder b; @@ -69,12 +85,12 @@ namespace mongo { } string errmsg = ""; - if ( check ) + if ( safe ) errmsg = conn->getLastError(); conn.done(); - if ( check && errmsg.size() ) + if ( safe && errmsg.size() ) throw UserException( (string)"error on Model::save: " + errmsg ); } diff --git a/client/model.h b/client/model.h index d6b6d6e649a..f3a63adaeef 100644 --- a/client/model.h +++ b/client/model.h @@ -47,7 +47,8 @@ namespace mongo { @return true if successful. */ virtual bool load(BSONObj& query); - virtual void save( bool check=false ); + virtual void save( bool safe=false ); + virtual void remove( bool safe=false ); protected: BSONObj _id; |