/// <summary> /// Returns index keys that should be used to ensure unique indexes on the collections /// </summary> /// <returns></returns> public IMongoIndexKeys GetIndexedKeys() { var keysBuilder = new MongoDB.Driver.Builders.IndexKeysBuilder(); //object's own props var props = this.GetType().GetProperties(); foreach (var p in props) { if (!PropsIgnoredOnQuery.Contains(p.Name)) { keysBuilder.Ascending(p.Name); } } return(keysBuilder); }
private void CreateExpirationIndex(string dbName, string collectionName, TimeSpan timeToLive) { var mongoClient = new MongoDB.Driver.MongoClient(connectionString); var mongoDatabase = MongoDB.Driver.MongoClientExtensions.GetServer(mongoClient).GetDatabase(dbName); var collection = mongoDatabase.GetCollection <CacheItem>(collectionName); var keys = new MongoDB.Driver.Builders.IndexKeysBuilder(); keys.Ascending("ExpireAt"); var options = new MongoDB.Driver.Builders.IndexOptionsBuilder(); options.SetName("ExpirationIndex"); options.SetTimeToLive(timeToLive); options.SetSparse(false); options.SetUnique(false); options.SetBackground(true); collection.CreateIndex(keys, options); }