/// <summary> /// Gets a MongoCollection instance representing a collection on this database /// with a default document type of TDefaultDocument. /// </summary> /// <param name="collectionSettings">The settings to use when accessing this collection.</param> /// <returns>An instance of MongoCollection.</returns> public virtual MongoCollection GetCollection(MongoCollectionSettings collectionSettings) { lock (_databaseLock) { MongoCollection collection; if (!_collections.TryGetValue(collectionSettings, out collection)) { var collectionDefinition = typeof(MongoCollection <>); var collectionType = collectionDefinition.MakeGenericType(collectionSettings.DefaultDocumentType); var constructorInfo = collectionType.GetConstructor(new Type[] { typeof(MongoDatabase), collectionSettings.GetType() }); collection = (MongoCollection)constructorInfo.Invoke(new object[] { this, collectionSettings }); _collections.Add(collectionSettings, collection); } return(collection); } }