查询 1月 7月 8月 的数据

list

- [0] { "$or" : [{ "JobDate" : { "$gte" : ISODate("2017-12-31T16:00:00Z"), "$lte" : ISODate("2018-01-31T15:59:59.999Z") } }, { "JobDate" : { "$gte" : ISODate("2018-06-30T16:00:00Z"), "$lte" : ISODate("2018-07-31T15:59:59.999Z") } }, { "JobDate" : { "$gte" : ISODate("2018-07-31T16:00:00Z"), "$lte" : ISODate("2018-08-31T15:59:59.999Z") } }] } MongoDB.Driver.IMongoQuery {MongoDB.Driver.QueryDocument}

{ "$or" : [{ "JobDate" : { "$gte" : ISODate("2017-12-31T16:00:00Z"), "$lte" : ISODate("2018-01-31T15:59:59.999Z") } }, { "JobDate" : { "$gte" : ISODate("2018-06-30T16:00:00Z"), "$lte" : ISODate("2018-07-31T15:59:59.999Z") } }, { "JobDate" : { "$gte" : ISODate("2018-07-31T16:00:00Z"), "$lte" : ISODate("2018-08-31T15:59:59.999Z") } }] }

or 都用这种拼接

or、是一大块 (数组)  里面的条件都是一段一段(每个元素)

mq为一个或者块 里面每一条数据  为一段时间区间 某一段 为  8月1号到8月30号 (所以用and)

然后在用或者组合起来

+ Query.Or(mq) { "$or" : [{ "JobDate" : { "$gte" : ISODate("2017-12-31T16:00:00Z"), "$lte" : ISODate("2018-01-31T15:59:59.999Z") } }, { "JobDate" : { "$gte" : ISODate("2018-06-30T16:00:00Z"), "$lte" : ISODate("2018-07-31T15:59:59.999Z") } }, { "JobDate" : { "$gte" : ISODate("2018-07-31T16:00:00Z"), "$lte" : ISODate("2018-08-31T15:59:59.999Z") } }] } MongoDB.Driver.IMongoQuery {MongoDB.Driver.QueryDocument}

组成一块

在与其他条件拼接

再看一个复杂点的

queryss

{ "$and" : [{ "$or" : [{ "Lineid" : /05698e90-8e6c-418d-9fd4-e50913c7a2df/ }, { "Lineid" : /063cd6b6-fed5-460a-a9e7-2d3e24c6ff3a/ }, { "Lineid" : /0a62d357-cb62-4701-8932-308f0caec7e1/ }, { "Lineid" : /0ce3471b-d143-4f3e-b186-69ab86ebef5c/ }, { "Lineid" : /0e3c7818-82cc-4494-bdcb-5bcfdfa698a9/ }, { "Lineid" : /0f193ce1-0344-443a-806f-1fce4fae6ed7/ }, { "Lineid" : /2a035070-c809-4603-b0f3-8479e81d4f97/ }, { "Lineid" : /2e6df343-fb9d-4ae9-b391-fcf90f21e6bf/ }, { "Lineid" : /3c9626d2-ddbb-4d4d-bc58-1a79d9ec0e23/ }, { "Lineid" : /44a82200-eb6a-4dcb-8fe6-60220618621f/ }, { "Lineid" : /491d94f1-0518-4cab-b5d0-3dfcfb58549b/ }, { "Lineid" : /4986a34a-ed90-4f7f-8136-8ad864ba23ee/ }, { "Lineid" : /525213a5-b171-4fca-a9d9-e4cb14f1c475/ }, { "Lineid" : /5d19f748-2df9-4893-aeb6-f1c524537af0/ }, { "Lineid" : /5d2809ec-feed-4c46-9bf0-3f9c3c9bc017/ }, { "Lineid" : /60bad064-3582-4744-bf16-e89a738583a6/ }, { "Lineid" : /68e69bfb-066d-4ef0-843f-251e27a1601a/ }, { "Lineid" : /6f1da95c-8e7f-4ae3-a4ce-799bcfe1d9d9/ }, { "Lineid" : /6fe4b7a8-9fae-431c-a48c-d681f21f1785/ }, { "Lineid" : /758cbc79-a80b-4c6f-b966-5fb08023a5fc/ }, { "Lineid" : /78e03e4c-7966-4875-b1a0-ffbea369e1c1/ }, { "Lineid" : /7c469ad9-fffd-4a7d-878f-cb8d36fb3110/ }, { "Lineid" : /88debfa9-d0fd-4a8c-9543-4b85b790b029/ }, { "Lineid" : /8eba7e67-508e-495f-a890-42d30c6f58c7/ }, { "Lineid" : /918c2762-f7f7-4206-af25-4bd97bb8be8a/ }, { "Lineid" : /93e1ee49-6be5-4967-bfea-29d76972ceb6/ }, { "Lineid" : /98e3cd50-356d-4c7d-b5b4-8f939cfc17ae/ }, { "Lineid" : /a0332eea-80fd-41c3-b47b-3f7ce38f9db9/ }, { "Lineid" : /aa151adb-bf0a-4533-96cb-d6a270665561/ }, { "Lineid" : /ab8d4f11-8008-4954-ad1b-977230360673/ }, { "Lineid" : /acfbe95c-91c8-4d97-b79b-b657eb2fcca3/ }, { "Lineid" : /d0e7254a-849e-4d82-bffa-49250402a9ac/ }, { "Lineid" : /d30b6d0e-f6a3-4b8e-852f-b8dc2a3fd0c9/ }, { "Lineid" : /d35ed599-6b5f-4f14-be7f-956a10acf6e7/ }, { "Lineid" : /d4cdb470-d593-4876-8e5d-bc4e84a9eed7/ }, { "Lineid" : /d6f93b2b-6ac8-4f51-9ca0-01f8fb07ed82/ }, { "Lineid" : /dbd33af7-3f29-4760-b418-6e99b22dcf08/ }, { "Lineid" : /e873a0d2-ff6b-432f-8a08-aca900938f2d/ }, { "Lineid" : /e8bb0b96-8818-4de2-bbdf-1ba0277477ab/ }, { "Lineid" : /ee82e295-7c20-4489-b28c-91e7a41aa78f/ }, { "Lineid" : /f24d23ae-2fef-4dbf-a763-11a6bcdf6ed9/ }, { "Lineid" : /f3fb0aab-826a-4425-b52b-043de11977a0/ }, { "Lineid" : /f73e5a94-dd1b-4c9a-93c5-f6ac2eaffd4c/ }, { "Lineid" : /f79ccef3-0a4e-47a1-9f08-be9e7f1c1c50/ }] }, { "$or" : [{ "Content" : /Change Vehicle/ }, { "Content" : /Change Crew/ }] }] }

db.Log_Line.find()   json 直接放在()里面 执行and[{or[{},{},{}...]}  ,  {or[{},{}]}]
A {or[{a1},{a2},{a3}...]}
B {or[{b1},{b2}]}

条件是  那条数据的 Id 为 (a1 或 a2 或 a3) 并且  Name 为(b1 或 b2)

Query.Matches("Content", "Change Vehicle")           { "Content" : /Change Vehicle/ }

 说明  new List<IMongoQuery>().Add()  是并且 

list.Add(Query.GTE("Date", dt));
list.Add(Query.LTE("Date", edt));

Date 大于等于 dt 并且 Date 小于等于 edt

要用或者 先组织好 并且的 数据

List<IMongoQuery> mq3 = new List<IMongoQuery>();

mq3.Add(Query.Matches("Content", "Change Vehicle"));

mq3.Add(Query.Matches("Content", "Change Crew"));

 list.Add(Query.Or(mq3));     然后 Query.Or  添加   就指定里面的集 全是或者了  然后添加到集合 并且

List<IMongoQuery> mq = new List<IMongoQuery>();

foreach (var item in LineInfos.Select(A => A.Id))
{
mq.Add(Query.Matches("Lineid", item.ToStr()));
}

 list.Add(Query.Or(mq));   mq里面集 全是或者  然后添加到集合 并且

说明mq并且mq3

但是mq mq3 里面的集是或者的

 

mongodb or and 条件拼凑 Query.And Query.Or的更多相关文章

  1. SpringMVC MongoDB之“基本文档查询(Query、BasicQuery)”

    一.简介 spring Data  MongoDB提供了org.springframework.data.mongodb.core.MongoTemplate对MongoDB的CRUD的操作,上一篇我 ...

  2. Elasticsearch由浅入深(九)搜索引擎:query DSL、filter与query、query搜索实战

    search api的基本语法 语法概要: GET /_search {} GET /index1,index2/type1,type2/_search {} GET /_search { , } h ...

  3. Hibernate中的query.setFirstResult(),query.setMaxResults();

    一.query.scroll()和query.setFirstResult(),query.setMaxResults();这两种方法都可以取到一定范围内的数据,用来数据分页显示.那么两者区别,以及两 ...

  4. MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields

    Different query operators in MongoDB treat null values differently. The examples on this page use th ...

  5. mongodb use where and custom function to query mongodb存储过程

    function name regexObjSubObjKey function code function(proto,value) { var match=false; var reg = new ...

  6. 【MongoDB初识】-条件操作符

    1.条件>,<,>=,<=在MongoDB中的写法 >:$gt,<:$lt,>=:$gte,<=:$lte,<>:$ne 具体使用方法: d ...

  7. How to get the underlying SSRS Report Query, reset query , add your own ranges and execute report [AX2012]

    Below is the small code snippet to get the underlying query of the SSRS report, reset query, prompt ...

  8. dojo 六 使用query dojo/query

    要使用query,就要引入dojo/query包.query可以根据Dom里节点的标签名.id名.class名来检索一个或多个节点.---------------------------------- ...

  9. Spring data jpa中Query和@Query分别返回map结果集

    引用: http://blog.csdn.net/yingxiake/article/details/51016234 http://blog.csdn.net/yingxiake/article/d ...

随机推荐

  1. [Codeforces 8D] Two Friends

    Brief Introduction: 有两人a.b,他们都在A点,a经过B点到C点,而b直接到C点.a走过的距离不超过la,b走过距离不超过lb,询问他们可能经过最长的公共距离. Algorithm ...

  2. Codeforces 919 E Congruence Equation

    题目描述 Given an integer xx . Your task is to find out how many positive integers nn ( 1<=n<=x1&l ...

  3. 【字符串哈希】bzoj3555 [Ctsc2014]企鹅QQ

    枚举每个位置,给每个串的前半部分一个哈希值,后半部分一个哈希值,若是它们均相等,则视为这两个串相似. 每次转移之后,排序一下就行了. O(L*n*log(n)). #include<cstdio ...

  4. 小白的Python之路 day5 os,sys模块详解

    os模块详解 1.作用: 提供对操作系统调用的接口 2.常用方法: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径os.chdir("dirname" ...

  5. python基础--常用模块与面向对象基础

    1常用模块 1.1 xml xml是实现不同语言或程序之间进行数据交换的协议 xml的格式如下: <?xml version="1.0"?> <data> ...

  6. Scala实战高手****第3课:在IDE下开发第一个Scala程序纯傻瓜式彻底透彻解析

  7. ctags 小记

    转:http://www.cnblogs.com/napoleon_liu/archive/2011/01/23/1942738.html 简介 ctags − Generate tag files ...

  8. SQL Server 跨数据库事务

      模拟三个库(同一个实例中),分别是DB1.DB2.DB3 整个事务的业务如下: 1.DB1写入表数据 2.DB2写入表数据 3.DB3调用存储过程写入表数据 4.每次写入表数据间隔模拟抛异常流程, ...

  9. [Git] 关于refs/for/ 和refs/heads/

    转载自: http://lishicongli.blog.163.com/blog/static/146825902013213439500/ 1.     这个不是git的规则,而是gerrit的规 ...

  10. iOS:Masonry 英文原档介绍

    Masonry 英文原档介绍: Masonry is still actively maintained, we are committed to fixing bugs and merging go ...