@@ -15,7 +15,6 @@ public class Collection : IMongoCollection
15
15
16
16
17
17
private Connection connection ;
18
- private Database db ;
19
18
20
19
private string name ;
21
20
public string Name {
@@ -41,13 +40,19 @@ public CollectionMetaData MetaData {
41
40
}
42
41
}
43
42
44
-
43
+ private Database db ;
44
+ private Database Db {
45
+ get {
46
+ if ( db == null )
47
+ db = new Database ( this . connection , this . dbName ) ;
48
+ return db ;
49
+ }
50
+ }
45
51
public Collection ( string name , Connection conn , string dbName )
46
52
{
47
53
this . name = name ;
48
54
this . connection = conn ;
49
55
this . dbName = dbName ;
50
- this . db = new Database ( this . connection , this . dbName ) ;
51
56
}
52
57
53
58
/// <summary>
@@ -101,7 +106,7 @@ public ICursor Find(Document spec, int limit, int skip, Document fields) {
101
106
/// A <see cref="MapReduce"/>
102
107
/// </returns>
103
108
public MapReduce MapReduce ( ) {
104
- return new MapReduce ( db , this . Name ) ;
109
+ return new MapReduce ( this . Db , this . Name ) ;
105
110
}
106
111
107
112
public MapReduceBuilder MapReduceBuilder ( ) {
@@ -125,7 +130,7 @@ public long Count(){
125
130
public long Count ( Document spec ) {
126
131
try {
127
132
//Database db = new Database(this.connection, this.dbName);
128
- Document ret = db . SendCommand ( new Document ( ) . Append ( "count" , this . Name ) . Append ( "query" , spec ) ) ;
133
+ Document ret = this . Db . SendCommand ( new Document ( ) . Append ( "count" , this . Name ) . Append ( "query" , spec ) ) ;
129
134
double n = ( double ) ret [ "n" ] ;
130
135
return Convert . ToInt64 ( n ) ;
131
136
} catch ( MongoCommandException ) {
@@ -150,7 +155,7 @@ public void Insert(Document doc){
150
155
}
151
156
152
157
public void Insert ( IEnumerable < Document > docs , bool safemode ) {
153
- if ( safemode ) db . ResetError ( ) ;
158
+ if ( safemode ) this . Db . ResetError ( ) ;
154
159
this . Insert ( docs ) ;
155
160
CheckPreviousError ( safemode ) ;
156
161
}
@@ -258,10 +263,6 @@ public void Update(Document doc, Document selector, int flags){
258
263
this . Update ( doc , selector , ( UpdateFlags ) flags ) ;
259
264
}
260
265
261
-
262
- public void UpdateAll ( Document doc , Document selector , bool safemode ) {
263
- throw new System . NotImplementedException ( ) ;
264
- }
265
266
/// <summary>
266
267
/// Runs a multiple update query against the database. It will wrap any
267
268
/// doc with $set if the passed in doc doesn't contain any '$' ops.
@@ -284,16 +285,22 @@ public void UpdateAll(Document doc, Document selector){
284
285
this . Update ( doc , selector , UpdateFlags . MultiUpdate ) ;
285
286
}
286
287
288
+
289
+ public void UpdateAll ( Document doc , Document selector , bool safemode )
290
+ {
291
+ throw new System . NotImplementedException ( ) ;
292
+ }
293
+
287
294
288
295
private void CheckError ( bool safemode ) {
289
296
if ( safemode ) {
290
- Document err = db . GetLastError ( ) ;
297
+ Document err = this . Db . GetLastError ( ) ;
291
298
if ( ErrorTranslator . IsError ( err ) ) throw ErrorTranslator . Translate ( err ) ;
292
299
}
293
300
}
294
301
private void CheckPreviousError ( bool safemode ) {
295
302
if ( safemode ) {
296
- Document err = db . GetPreviousError ( ) ;
303
+ Document err = this . Db . GetPreviousError ( ) ;
297
304
if ( ErrorTranslator . IsError ( err ) ) throw ErrorTranslator . Translate ( err ) ;
298
305
}
299
306
}
0 commit comments