public static Db ( string ObjName ) : IMongoDatabase | ||
ObjName | string | |
리턴 | IMongoDatabase |
public static IEnumerable <string> GetCollentionNames(string DbName) { var colNames = new List <string>(); MongoMapperHelper.Db(DbName).ListCollectionsAsync().Result.ForEachAsync(F => colNames.Add(F["name"].AsString)); return(colNames.Where(C => !C.ToUpper().StartsWith("SYSTEM"))); }
public static bool CollectionExists(string Name) { var filter = new BsonDocument("name", Name); //filter by collection name var collections = MongoMapperHelper.Db(Name).ListCollectionsAsync(new ListCollectionsOptions { Filter = filter }).GetAwaiter().GetResult().ToListAsync().Result; //check for existence return(collections.Any()); }
private long FindAndModifyResult(string ObjName) { var result = MongoMapperHelper.Db("Counters", true) .GetCollection <BsonDocument>("Counters") .FindOneAndUpdateAsync( Builders <BsonDocument> .Filter.Eq("document", ObjName), Builders <BsonDocument> .Update.Inc("last", (long)1), new FindOneAndUpdateOptions <BsonDocument>() { IsUpsert = true, ReturnDocument = ReturnDocument.After } ).Result; return(result["last"].AsInt64); }
public static IMongoCollection <T> GetPrimaryCollection <T>(string Name) { Name = GetCollectioName(Name); string key = string.Format("{0}|{1}|{2}", Name, typeof(T).FullName, Configuration.ConfigManager.GetConfigurationKey()); if (PrimaryCollections.ContainsKey(key)) { return((IMongoCollection <T>)PrimaryCollections[key]); } lock (LockObject) { if (!PrimaryCollections.ContainsKey(key)) { var collection = MongoMapperHelper.Db(Name, true).GetCollection <T>(Name); PrimaryCollections.Add(key, collection); } return((IMongoCollection <T>)PrimaryCollections[key]); } }