정리중/Big Data

MongoDB C# Match 조건 Like 검색 (대소문자 무시 검색)

위즈 2014. 4. 26. 11:10

Mongodb C# Driver에서 간단하게 Like 검색 하는 방법


MongoDB.Driver.MongoDatabase MGOCDB=mongoDB;

MongoDB.Driver.MongoCollection MGOCOL=MGOCDB.GetCollection<MongoDB.Bson.BsonDocument>("TestCollection");

// keyword로 시작하는 단어 검색

MongoDB.Driver.MongoCursor mcur = MGOCOL.FindAs<MongoDB.Driver.MongoCursor>(MongoDB.Driver.Builders.Query.Matches("TargetNames", keyword+".*"));

// 대소문자 구분 하지 않음

MongoDB.Bson.BsonRegularExpression regkey = new MongoDB.Bson.BsonRegularExpression("*."+keyword+".*", "i");

MongoDB.Bson.BsonDocument mdoc = MGOCOL.FindOneAs<MongoDB.Bson.BsonDocument>(MongoDB.Driver.Builders.Query.Matches("TargetNames", regkey);


정규식을 이용한 검색이 가능합니다.