查询 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. IActionResult

  2. HDU 5938 Four Operations 【字符串处理,枚举,把数字字符串变为数值】

    Problem Description Little Ruins is a studious boy, recently he learned the four operations! Now he ...

  3. 洛谷 P3041 [USACO12JAN] Video Game Combos

    题目描述 Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only v ...

  4. 【动态规划】bzoj1649 [Usaco2006 Dec]Cow Roller Coaster

    很像背包. 这种在一个数轴上进行操作的题常常需要对区间排序. f[i][j]表示距离到i时,花费为j时的权值之和. f[x[i]+l[i]][j+c[i]]=max{f[x[i]][j]+w[i]}( ...

  5. 【可持久化Trie】模板

    总算找到个能看懂的了,orz Lavender. #define INF 2147483647 #define N 100001 #define MAXBIT 31 int root[N],ch[N* ...

  6. iOS开发——使用Autolayout弹出键盘

    参考: http://segmentfault.com/q/1010000002420050 http://blog.csdn.net/qq448631961/article/details/4034 ...

  7. CentOS 6.9系统时间和硬件时间设置(转)

    总结一下hwclock,这个容易晕: 1)/etc/sysconfig/clock 文件,只对 hwclock 命令有效,且只在系统启动和关闭的时候才有用(修改了其中的 UTC=true 到 UTC= ...

  8. ethtool 命令输出的注意点--网卡参数

    http://blog.csdn.net/msdnchina/article/details/70339689

  9. 如何使用 vimdiff 来 git diff

    git config --global diff.tool vimdiffgit config --global difftool.prompt falsegit config --global al ...

  10. 【InteillJ IDEA】Git的安装+同步项目到GitHub上

    需要的工具: 1.InteillJ IDEA 2.Git 3.GitHub帐号 步骤: 1.下载Git 下载地址:https://git-scm.com/downloads 安装完成后 勾选Launc ...