protected bool Exists(OneOptions options) { if (options == null) { throw new ArgumentNullException("options"); } var findArgs = new FindOneArgs { Query = options.GetMongoQuery(_getIdValue), Fields = Fields.Include(CommonFieldNames.Id), ReadPreference = ReadPreference.Primary }; return(_collection.FindOneAs <T>(findArgs) != null); }
protected TModel FindOne <TModel>(OneOptions options) where TModel : class, new() { if (options == null) { throw new ArgumentNullException("options"); } TModel result = null; if (options.UseCache) { result = Cache.Get <TModel>(GetScopedCacheKey(options.CacheKey)); } if (result != null) { return(result); } var findArgs = new FindOneArgs { Query = options.GetMongoQuery(_getIdValue), Fields = Fields.Include(options.Fields.ToArray()) }; var mongoOptions = options as MongoOptions; if (mongoOptions != null && mongoOptions.SortBy != null) { findArgs.SortBy = mongoOptions.SortBy; } if (mongoOptions != null && mongoOptions.ReadPreference != null) { findArgs.ReadPreference = mongoOptions.ReadPreference; } result = _collection.FindOneAs <TModel>(findArgs); if (result != null && options.UseCache) { Cache.Set(GetScopedCacheKey(options.CacheKey), result, options.GetCacheExpirationDate()); } return(result); }