00001
00002
00003
00004
00005
00006
00023 #pragma once
00024
00025 #include "../pch.h"
00026 #include "client.h"
00027 #include "db.h"
00028
00029 namespace mongo {
00030
00031 const BSONObj reverseNaturalObj = BSON( "$natural" << -1 );
00032
00033 class Cursor;
00034 class CoveredIndexMatcher;
00035
00039 struct Helpers {
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 static void ensureIndex(const char *ns, BSONObj keyPattern, bool unique, const char *name);
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 static bool findOne(const char *ns, const BSONObj &query, BSONObj& result, bool requireIndex = false);
00066 static DiskLoc findOne(const char *ns, const BSONObj &query, bool requireIndex);
00067
00072 static bool findById(Client&, const char *ns, BSONObj query, BSONObj& result ,
00073 bool * nsFound = 0 , bool * indexFound = 0 );
00074
00075
00076
00077 static DiskLoc findById(NamespaceDetails *d, BSONObj query);
00078
00086 static bool getSingleton(const char *ns, BSONObj& result);
00087 static void putSingleton(const char *ns, BSONObj obj);
00088 static void putSingletonGod(const char *ns, BSONObj obj, bool logTheOp);
00089 static bool getFirst(const char *ns, BSONObj& result) { return getSingleton(ns, result); }
00090 static bool getLast(const char *ns, BSONObj& result);
00091
00097 static void upsert( const string& ns , const BSONObj& o );
00098
00102 static bool isEmpty(const char *ns, bool doAuth=true);
00103
00104
00105 static BSONObj toKeyFormat( const BSONObj& o , BSONObj& key );
00106
00107 class RemoveCallback {
00108 public:
00109 virtual ~RemoveCallback() {}
00110 virtual void goingToDelete( const BSONObj& o ) = 0;
00111 };
00112
00113 static long long removeRange( const string& ns , const BSONObj& min , const BSONObj& max , bool yield = false , bool maxInclusive = false , RemoveCallback * callback = 0 );
00114
00115
00116
00117
00118 static void emptyCollection(const char *ns);
00119
00120 };
00121
00122 class Database;
00123
00124
00125 class DbSet {
00126 public:
00127 DbSet( const string &name = "", const BSONObj &key = BSONObj() ) :
00128 name_( name ),
00129 key_( key.getOwned() ) {
00130 }
00131 ~DbSet();
00132 void reset( const string &name = "", const BSONObj &key = BSONObj() );
00133 bool get( const BSONObj &obj ) const;
00134 void set( const BSONObj &obj, bool val );
00135 private:
00136 string name_;
00137 BSONObj key_;
00138 };
00139
00140
00144 class RemoveSaver : public Helpers::RemoveCallback , boost::noncopyable {
00145 public:
00146 RemoveSaver( const string& type , const string& ns , const string& why);
00147 ~RemoveSaver();
00148
00149 void goingToDelete( const BSONObj& o );
00150
00151 private:
00152 path _root;
00153 path _file;
00154 ofstream* _out;
00155
00156 };
00157
00158
00159 }