private FilterDefinition <HotelBasic> GetFilters(FilterModel filter) { var builder = Builders <HotelBasic> .Filter; var filters = builder.Exists(x => x.name); if (!string.IsNullOrEmpty(filter.City)) { filters = builder.Regex(x => x.city, BsonRegularExpression.Create(new Regex(filter.City, RegexOptions.IgnoreCase))); } if (!string.IsNullOrEmpty(filter.State)) { filters = filters & builder.Regex(x => x.metroAreaName, BsonRegularExpression.Create(new Regex(filter.State, RegexOptions.IgnoreCase))); } if (filter.Guests != 0) { filters = filters & builder.Gt(x => x.totalSleepingRoom, filter.Guests / 2); } if (filter.MetricValue != 0) { filters = filters & builder.Gt(x => x.largestMeetingSpace.metricValue, filter.MetricValue); } filters = filters & builder.Where(x => x.DateDeleted == null); return(filters); }
// Insert a list of documenst in database named "testdb", in a collection named "travel" // find the recent second-two travlers with name starting with S order by name desc public void MongoCrud_10_2_Find_Second_two_Recent_Passengers_with_Name_Starting_With_S_Order_By_Name_Dsc() { #region mongoConnection travelCollection = new MongoClient(_runner.ConnectionString).GetDatabase("testdb").GetCollection <AirTravel>("travel"); #endregion #region data preparation InsertTravelDetails(); #endregion int pageSize = 2; int pageNumber = 1; var filter = Builders <AirTravel> .Filter.Regex(x => x.FirstName, BsonRegularExpression.Create(new Regex("S.*"))); var sortDefinition = Builders <AirTravel> .Sort.Descending(x => x.FirstName); var result = travelCollection.Find(filter).Sort(sortDefinition) .Skip(pageSize * pageNumber) .Limit(pageSize).ToList(); #region verification TravelOperationVerifier.Verify_Passengers_NameStarting_with_S(_runner.ConnectionString, result); #endregion #region data cleanup cleanUpTravelCollection(); #endregion }
private FilterDefinition <Campaign> GetFilter(string term) { return(string.IsNullOrWhiteSpace(term) ? Builders <Campaign> .Filter.Empty : Builders <Campaign> .Filter.Regex("Name", BsonRegularExpression.Create(new Regex(term, RegexOptions.IgnoreCase)))); }
public void TestBsonRegularExpressionConstructors() { var regex = BsonRegularExpression.Create("pattern"); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("", regex.Options); regex = BsonRegularExpression.Create("/pattern/i"); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("i", regex.Options); regex = BsonRegularExpression.Create(@"/pattern\/withslash/i"); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern/withslash", regex.Pattern); Assert.AreEqual("i", regex.Options); regex = BsonRegularExpression.Create("pattern", "i"); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("i", regex.Options); regex = BsonRegularExpression.Create(new Regex("pattern")); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("", regex.Options); regex = BsonRegularExpression.Create(new Regex("pattern", RegexOptions.IgnoreCase)); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("i", regex.Options); }
public static Domain.PhysicianCollection GetPhysiciansByName(string firstName, string lastName) { YellowstonePathology.Business.Domain.PhysicianCollection result = new YellowstonePathology.Business.Domain.PhysicianCollection(); YellowstonePathology.Business.Mongo.Server server = new Business.Mongo.TestServer(YellowstonePathology.Business.Mongo.MongoTestServer.LISDatabaseName); MongoCollection collection = server.Database.GetCollection <BsonDocument>("Physician"); MongoCursor cursor = null; if (string.IsNullOrEmpty(firstName) == false) { cursor = collection.FindAs <BsonDocument>(Query.And(Query.Matches("LastName", BsonRegularExpression.Create("^" + lastName + ".*", "i")), Query.Matches("FirstName", BsonRegularExpression.Create("^" + firstName + ".*", "i")))).SetSortOrder(SortBy.Ascending("LastName", "FirstName")); } else { cursor = collection.FindAs <BsonDocument>(Query.Matches("LastName", BsonRegularExpression.Create("^" + lastName + ".*", "i"))).SetSortOrder(SortBy.Ascending("LastName", "FirstName")); } foreach (BsonDocument bsonDocument in cursor) { YellowstonePathology.Business.Domain.Physician physician = new YellowstonePathology.Business.Domain.Physician(); YellowstonePathology.Business.Mongo.BSONPropertyWriter.Write(bsonDocument, physician); result.Add(physician); } return(result); }
public void TestRegularExpressionStrict() { var tests = new TestData <BsonRegularExpression>[] { new TestData <BsonRegularExpression>(null, "null"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create(""), "{ \"$regex\" : \"\", \"$options\" : \"\" }"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create("a"), "{ \"$regex\" : \"a\", \"$options\" : \"\" }"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create("a/b"), "{ \"$regex\" : \"a/b\", \"$options\" : \"\" }"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create("a\\b"), "{ \"$regex\" : \"a\\\\b\", \"$options\" : \"\" }"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create("a", "i"), "{ \"$regex\" : \"a\", \"$options\" : \"i\" }"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create("a", "m"), "{ \"$regex\" : \"a\", \"$options\" : \"m\" }"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create("a", "x"), "{ \"$regex\" : \"a\", \"$options\" : \"x\" }"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create("a", "s"), "{ \"$regex\" : \"a\", \"$options\" : \"s\" }"), new TestData <BsonRegularExpression>(BsonRegularExpression.Create("a", "imxs"), "{ \"$regex\" : \"a\", \"$options\" : \"imxs\" }"), }; var jsonSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }; foreach (var test in tests) { var json = test.Value.ToJson(jsonSettings); Assert.AreEqual(test.Expected, json); Assert.AreEqual(test.Value, BsonSerializer.Deserialize <BsonRegularExpression>(json)); } }
/// <summary> /// Busca uma lista de tecnologias que o nome seja parecido com o texto digitado /// </summary> /// <param name="name">texto a ser procurado</param> /// <returns></returns> public async Task <List <Techie> > SearchTechiesPerName(string name) { var filter = FilterBuilder.Regex(a => a.Name, BsonRegularExpression.Create(new Regex(name, RegexOptions.IgnoreCase))) & FilterBuilder.Exists(a => a.DeletedAt, false); return(await Collection.Find(filter).ToListAsync()); }
/////////////////////////////////////////////////////////////// // SELECT All DATA ////////////////////////////////////////////////////////////// public static List <User> SearchUserbyLocation(string Location) { List <User> lst = new List <User>(); MongoCollection <BasicInfo> objCollection = db.GetCollection <BasicInfo>("c_BasicInfo"); var query = Query.Matches("CurrentCity", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + Location + ""))); foreach (BasicInfo item in objCollection.Find(query)) { MongoCollection <User> objUserCollection = db.GetCollection <User>("c_User"); UserBO objClass = new UserBO(); foreach (User Useritem in objUserCollection.Find(Query.EQ("_id", item.UserId))) { lst.Add(Useritem); break; } } return(lst.ToList()); }
/////////////////////////////////////////////////////////////// // SELECT All DATA ////////////////////////////////////////////////////////////// public static List <User> SearchUserList(string Name, string userid) { List <User> lst = new List <User>(); MongoCollection <User> objCollection = db.GetCollection <User>("c_User"); string[] words = Name.Split(' '); foreach (string word in words) { var query = Query.Or( Query.Matches("FirstName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + word + ""))), Query.Matches("LastName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + word + ""))), Query.Matches("Email", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + Name + "")))); var query2 = Query.And(query, Query.NE("_id", ObjectId.Parse(userid))); foreach (User item in objCollection.Find(query2).Distinct()) { lst.Add(item); } } return(lst.Distinct().ToList()); }
/////////////////////////////////////////////////////////////// // SELECT All DATA ////////////////////////////////////////////////////////////// public static List <User> SearchUserbyWorkSpace(string WorkSpace) { List <User> lst = new List <User>(); MongoCollection <Employer> objCollection = db.GetCollection <Employer>("c_Employer"); var query = Query.Matches("Organization", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + WorkSpace + ""))); foreach (Employer item in objCollection.Find(query)) { MongoCollection <User> objUserCollection = db.GetCollection <User>("c_User"); UserBO objClass = new UserBO(); foreach (User Useritem in objUserCollection.Find(Query.EQ("_id", item.UserId))) { lst.Add(Useritem); break; } } return(lst.ToList()); }
public string[] GetLocation(string prefixText, int count) { List <string> lst = new List <string>(); MongoCollection <BasicInfo> objCollection = BaseClass.db.GetCollection <BasicInfo>("c_BasicInfo"); var query = Query.Matches("HomeTown", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))); var cursor = objCollection.Find(query); cursor.Limit = 5; System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; System.Globalization.TextInfo txtInfo = cultureInfo.TextInfo; foreach (var item in cursor) { lst.Add(txtInfo.ToTitleCase(item.HomeTown)); } /* var query2 = Query.Matches("HomeTown", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))); * * var cursor2 = objCollection.Find(query2); * cursor2.Limit = 5; * foreach (var item in cursor) * { * lst.Add(item.HomeTown); * * }*/ return(lst.Distinct().Take(5).ToArray()); }
/////////////////////////////////////////////////////////////// // SELECT All DATA ////////////////////////////////////////////////////////////// public static List <User> SearchUserbyEducation(string Education, int year) { List <User> lst = new List <User>(); MongoCollection <University> objCollection = db.GetCollection <University>("c_University"); var query = Query.Or( Query.Matches("UniversityName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + Education + ""))), Query.EQ("ClassYear", year)); foreach (University item in objCollection.Find(query)) { MongoCollection <User> objUserCollection = db.GetCollection <User>("c_User"); UserBO objClass = new UserBO(); foreach (User Useritem in objUserCollection.Find(Query.EQ("_id", item.UserId))) { lst.Add(Useritem); break; } } return(lst.ToList()); }
// Insert a list of documenst in database named "testdb", in a collection named "travel" // find the recent second-two recent travlers with name starting with S order by travel date desc // project first name , last name and latest travelhistory public void MongoCrud_11_1_Find_Second_two_Recent_Passengers_Starting_With_S_OrderBy_TravelDate_Dsc_Project() { #region mongoConnection travelCollection = new MongoClient(_runner.ConnectionString).GetDatabase("testdb").GetCollection <AirTravel>("travel"); #endregion #region data preparation InsertTravelDetails(); #endregion var filter = Builders <AirTravel> .Filter.Regex(x => x.FirstName, BsonRegularExpression.Create(new Regex("S.*"))); var result = travelCollection.Find(filter).Sort("{\"TravelHistory.TravelDate\" : -1 }") .Project(x => new { x.FirstName, x.LastName, hist = x.TravelHistory.FirstOrDefault() }) .Skip(2) .Limit(2) .ToList(); #region verification Assert.True(result.ElementAt(0).hist.TravelDate > result.ElementAt(1).hist.TravelDate); #endregion #region data cleanup cleanUpTravelCollection(); #endregion }
/// <summary> /// Mq消费者client status /// </summary> /// <param name="limit"></param> /// <param name="offset"></param> /// <param name="search"></param> /// <returns></returns> public ActionResult ConsumerInfo(int limit, int offset, string search = null) { var query = Query.Null; if (!string.IsNullOrEmpty(search)) { query = Query.Matches("ip", BsonRegularExpression.Create($"/{search}/")); } var total = dataOp.FindCount(MQConsumerInfo, query); var rows = new List <dynamic>(); if (total > 0) { var sortBy = new SortByDocument { { "isStart", -1 }, { "lastStartTime", -1 }, { "lastEndTime", -1 }, { "ip", 1 } }; var docs = dataOp.FindLimitByQuery(MQConsumerInfo, query, sortBy, offset, limit); foreach (var doc in docs) { var consumerId = doc.Int("consumerId"); var ip = doc.String("ip"); var queueType = doc.String("queueType"); var isStart = doc.Int("isStart"); if (isStart > 0) { SystemMonitorBll._().SetIp(ip); } var lastStartTime = doc.String("lastStartTime"); var lastEndTime = doc.String("lastEndTime"); var lastExecTime = doc.String("lastExecTime"); rows.Add(new { consumerId, ip, queueType, isStart, lastStartTime, lastEndTime, lastExecTime }); } } return(Json(new { total, rows }, JsonRequestBehavior.AllowGet)); }
public async Task <IEnumerable <User> > GetUsersByField(string fieldName, object fieldValue) { var filter = Builders <User> .Filter.Regex(fieldName, BsonRegularExpression.Create(new Regex(fieldValue?.ToString()))); var result = await _context.User.Find(filter).ToListAsync(); return(result); }
private FilterDefinition <DefaultTag> FilterByUserAndName(string userId, string term) { var regex = BsonRegularExpression.Create( new Regex(term, RegexOptions.IgnoreCase)); return(Builders <DefaultTag> .Filter .Regex(t => t.Name, regex) & FilterByUser(userId)); }
public void Find_passengers_with_name_starting_with_S() { PrepareDatabase(); var filter = Builders <AirTravel> .Filter.Regex(x => x.FirstName, BsonRegularExpression.Create(new Regex("S.*"))); var document = travelCollection.Find(filter).ToList(); Assert.AreNotEqual(document, null); Assert.AreEqual(document.Count, 4); }
/// <summary> /// Gets all activity log items /// </summary> /// <param name="createdOnFromUtc">Log item creation from; null to load all users</param> /// <param name="createdOnToUtc">Log item creation to; null to load all users</param> /// <param name="email">User Email</param> /// <param name="username">User username</param> /// <param name="activityLogType">Activity log type system keyword</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>Activity log collection</returns> /// <remarks></remarks> public virtual PagedList <ActivityLog> GetAllActivities(DateTime?createdOnFromUtc = null, DateTime?createdOnToUtc = null, string email = "", string username = "", string activityLogType = "", int pageIndex = 0, int pageSize = int.MaxValue) { var filters = new List <IMongoQuery>(); var userIds = new List <ObjectId>(); if (!string.IsNullOrEmpty(username)) { var usernameRegex = new Regex(username, RegexOptions.IgnoreCase); userIds.AddRange(_userCollection.Find(Query <User> .EQ(x => x.Username, BsonRegularExpression.Create(usernameRegex))).SetFields(Fields <User> .Include(x => x.Id)).Select(x => x.Id)); } if (!string.IsNullOrEmpty(email)) { var emailRegex = new Regex(email, RegexOptions.IgnoreCase); userIds.AddRange(_userCollection.Find(Query <User> .EQ(x => x.Email, BsonRegularExpression.Create(emailRegex))).SetFields(Fields <User> .Include(x => x.Id)).Select(x => x.Id)); } if (!string.IsNullOrEmpty(username) || !string.IsNullOrEmpty(email)) { // we are searching for certain user ids filters.Add(Query <ActivityLog> .In(x => x.UserId, userIds.Select(x => (ObjectId?)x))); } if (!string.IsNullOrEmpty(activityLogType)) { var activity = _activityLogTypeCollection.Find(Query <ActivityLogType> .EQ(x => x.SystemKeyword, activityLogType)).SetFields(Fields <ActivityLogType> .Include(x => x.Id)).FirstOrDefault(); if (activity != null) { filters.Add(Query <ActivityLog> .EQ(x => x.ActivityLogTypeId, activity.Id)); } } if (createdOnFromUtc.HasValue) { filters.Add(Query <ActivityLog> .GTE(x => x.CreatedOnUtc, createdOnFromUtc.Value)); } if (createdOnToUtc.HasValue) { filters.Add(Query <ActivityLog> .LTE(x => x.CreatedOnUtc, createdOnToUtc.Value)); } var query = filters.Any() ? Query.And(filters) : null; var total = query != null?_activityLogCollection.Count(query) : _activityLogCollection.Count(); var logs = (query != null ? _activityLogCollection.Find(query) : _activityLogCollection.FindAll()) .SetSkip(pageIndex * pageSize) .SetLimit(pageSize) .ToList(); return(new PagedList <ActivityLog>(logs, pageIndex, pageSize, (int)total)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static BsonValue Regex(object value) { Regex val = (Regex)value; if (val == null) { return(BsonNull.Value); } return(BsonRegularExpression.Create(val)); }
public static IEnumerable <T> FindLike <T>(this MongoCollection <T> collection, string propertyName, string value, string applicationName, int startIndex, int pageSize) { var cursor = collection.Find(Query.And(Query.Matches(propertyName, BsonRegularExpression.Create(new Regex(value))), Query.EQ("ApplicationName", applicationName))); if (pageSize > 0) { cursor.SetSkip(startIndex).SetLimit(pageSize); } return(cursor); }
/// <summary> /// Remove all items from cache with keys matching the given regex /// </summary> /// <param name="keyRegex"> A regex indicating the keys of which items to remove </param> public override void RegexClear(string keyRegex) { // Insert prefix into regular expression var prefixedKeyRegex = keyRegex.Insert( keyRegex.StartsWith("^") ? 1 : 0, System.Text.RegularExpressions.Regex.Escape(this.keyPrefix)); var query = Query.Matches("_id", BsonRegularExpression.Create(prefixedKeyRegex)); this.mongoProvider.DefaultCollection.Remove(query); }
public static Boolean deleteSubscription(string publisherId, string subscriberId) { MongoCollection <Subscription> objCollection = db.GetCollection <Subscription>("c_Subscription"); var query = Query.And( Query.Matches("PublisherUserId", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + publisherId + ""))), Query.Matches("SubscriberUserId", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + subscriberId + "")))); var result = objCollection.FindAndRemove(query, SortBy.Ascending("_id")); return(true); }
/// <summary> /// Get user by email /// </summary> /// <param name="email">Email</param> /// <returns>User</returns> /// <remarks></remarks> public virtual User GetUserByEmail(string email) { if (string.IsNullOrEmpty(email)) { return(null); } var emailRegex = new Regex(email, RegexOptions.IgnoreCase); return(_userCollection.FindOne(Query <User> .EQ(x => x.Email, BsonRegularExpression.Create(emailRegex)))); }
/// <summary> /// Get user by username /// </summary> /// <param name="username">Username</param> /// <returns>User</returns> /// <remarks></remarks> public virtual User GetUserByUsername(string username) { if (username.IsNullOrWhiteSpace()) { return(null); } var usernameRegex = new Regex(username, RegexOptions.IgnoreCase); return(_userCollection.FindOne(Query <User> .EQ(x => x.Username, BsonRegularExpression.Create(usernameRegex)))); }
public void TestBsonRegularExpressionConstructors() { var regex = BsonRegularExpression.Create("pattern"); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("", regex.Options); regex = BsonRegularExpression.Create("/pattern/i"); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("i", regex.Options); regex = BsonRegularExpression.Create(@"/pattern\/withslash/i"); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern/withslash", regex.Pattern); Assert.AreEqual("i", regex.Options); regex = BsonRegularExpression.Create("pattern", "i"); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("i", regex.Options); regex = BsonRegularExpression.Create(new Regex("pattern")); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("", regex.Options); regex = BsonRegularExpression.Create(new Regex("pattern", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline)); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("imxs", regex.Options); regex = BsonRegularExpression.Create(new Regex("pattern", RegexOptions.IgnoreCase)); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("i", regex.Options); regex = BsonRegularExpression.Create(new Regex("pattern", RegexOptions.Multiline)); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("m", regex.Options); regex = BsonRegularExpression.Create(new Regex("pattern", RegexOptions.IgnorePatternWhitespace)); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("x", regex.Options); regex = BsonRegularExpression.Create(new Regex("pattern", RegexOptions.Singleline)); Assert.IsInstanceOf <BsonRegularExpression>(regex); Assert.AreEqual("pattern", regex.Pattern); Assert.AreEqual("s", regex.Options); }
/// <summary> /// Sugere uma tecnologia com base em uma palavra chave /// </summary> /// <param name="text">palavra chave</param> /// <returns></returns> public async Task <List <Techie> > SugestTechie(string text) { var filter = FilterBuilder.Regex(a => a.Name, BsonRegularExpression.Create(new Regex(text, RegexOptions.IgnoreCase))) & FilterBuilder.Exists(a => a.DeletedAt, false); var sort = SortBuilder.Ascending(a => a.Name); return(await Collection .Find(filter) .Sort(sort) .Limit(5) .ToListAsync()); }
public List <Destination> SearchDestinations(string criteria) { string country = DestinationPropertiesNames.Country; string place = DestinationPropertiesNames.PlaceName; var query = Query.Or(Query.Matches(country, BsonRegularExpression.Create(new Regex(criteria, RegexOptions.IgnoreCase))), Query.Matches(place, BsonRegularExpression.Create(new Regex(criteria, RegexOptions.IgnoreCase)))); List <Destination> destinations = collection.Find(query).ToList(); return(destinations); }
public override async Task <IEnumerable <Product> > GetAll(string query = null) { var builder = new FilterDefinitionBuilder <Product>(); var filter = builder.Empty; if (!String.IsNullOrWhiteSpace(query)) { filter = filter & builder.Regex(x => x.Name, BsonRegularExpression.Create(new Regex(query, RegexOptions.IgnoreCase))); } return(await Items.Find(filter).ToListAsync()); }
public static void Verify_Passengers_NameStarting_with_S(string connectionString, List <AirTravel> TravelDocument) { var filter = Builders <AirTravel> .Filter.Regex(x => x.FirstName, BsonRegularExpression.Create(new Regex("S.*"))); var sortDefinition = Builders <AirTravel> .Sort.Descending(x => x.FirstName); var result = GetCollection(connectionString).Find(filter).Sort(sortDefinition) .Skip(2) .Limit(2).ToList(); Assert.AreEqual(2, TravelDocument.Count); Assert.AreEqual(TravelDocument.ElementAt(1).FirstName, result.ElementAt(1).FirstName, "sorting not proper"); }
public string getByProfile(string profile) { //Query needed to get the result var query = Query.Matches("name", BsonRegularExpression.Create(new Regex(profile))); JoinCollections Join = new JoinCollections(); Join.Select("Profiles") .Join("Users", "Creator", "_id", "name=>Creator"); return(Join.Find(query)); }