在MongoDB中,如果我想做一个LIKE语句,我会这样做:
db.users.find({"name": /m/})
它很棒!!我如何在c#中完成?
Builders<BsonDocument>.Filter.Eq("city", "/M/");
不退货!
答案 0 :(得分:2)
将 Filter Definition Builder 与正则表达式过滤器 Regex()
一起使用,如下所示:
var search = "M";
var builder = Builders<BsonDocument>.Filter;
var filter = builder.Regex("city", search);
答案 1 :(得分:1)
//Use Regex,
var search = "M";
var builder = Builders<BsonDocument>.Filter;
var filter = builder.Regex("city", "^" + search + ".*");
// ^ - For Starts with
// . - any character
// * - for any number of previous "."