当前位置:Gxlcms > 数据库问题 > MongoDB Driver 中通过过滤器实现文档查询

MongoDB Driver 中通过过滤器实现文档查询

时间:2021-07-01 10:21:17 帮助过:13人阅读

TheTimeStamp = TimeHelper.GetTimeStamp(requestTime.AddHours(-4));

           2、构建查询过滤器

   var filterBuilder = Builders<PageColllection>.Filter;
   var filter = filterBuilder.Eq(p => p.PXID, wid) & filterBuilder.Eq(p => p.ip, ip) & filterBuilder.Gte(p => p.unixTime, unixtemp) & filterBuilder.Eq(p => p.state, 1) & filterBuilder.Eq(p => p.URL, url);

  方法如下所示:

 public long AntiEvilclickRuleOne(string ip, int wid, DateTime requestTime, string url)
        {
            try
            {
                long result = 0;
                long unixtemp = 0;
                string TheTimeStamp = TimeHelper.GetTimeStamp(requestTime.AddHours(-4));
                if (!long.TryParse(TheTimeStamp, out unixtemp))
                {
                    return 0;
                }
                var filterBuilder = Builders<PageColllection>.Filter;
                var filter = filterBuilder.Eq(p => p.PXID, wid) & filterBuilder.Eq(p => p.ip, ip) & filterBuilder.Gte(p => p.unixTime, unixtemp) & filterBuilder.Eq(p => p.state, 1) & filterBuilder.Eq(p => p.URL, url);
result
= MongoDbHelper.GetDb().GetCollection<PageColllection>("PageColllection").Find(filter).CountDocuments(); return result; } catch (Exception ex) { AddLog.addLog_db("PageColllectionBLL.CheckRecordsByMemberIDLineID异常", ex.Message); return 0; } }

 

    

 

MongoDB Driver 中通过过滤器实现文档查询

标签:过滤   大于   rgb   ESS   one   string   request   条件查询   amp   

人气教程排行