查询 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. ACM竞赛常用头文件模板-备忘

    备忘. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  2. Codeforces 651 B. Beautiful Paintings

    B. Beautiful Paintings   time limit per test 1 second memory limit per test 256 megabytes input stan ...

  3. php中parse_url函数的源码及分析

    前言 看师傅们的文章时发现,parse_url出现的次数较多,单纯parse_url解析漏洞的考题也有很多,在此研究一下源码(太菜了看不懂,待日后再补充Orz) 源码 PHPAPI php_url * ...

  4. 湖南师范大学2018年大学生程序设计竞赛新生赛 A 齐神和心美的游戏【hash】

    [链接]:A [题意]:给你n个数的序列和k.判断是否可以三个数组成k(同一个数可以拿多次) [分析]:每个数vis记录一下.2层循环.两数之和不超过k以及剩下的数出现在序列中那么ok. [代码]: ...

  5. Jenkins集成SonarQube

    sonar安装配置 准备软件包 安装 mysql5.6+ 创建数据库sonar,字符集编码utf8 新建用户如heboan 因为sonarqube不能使用root用户运行 调整系统参数,/etc/se ...

  6. ASP.NET Core 2.2 基础知识(十二) 发送 HTTP 请求

    可以注册 IHttpClientFactory 并将其用于配置和创建应用中的 HttpClient 实例. 这能带来以下好处: 提供一个中心位置,用于命名和配置逻辑 HttpClient 实例. 例如 ...

  7. mysql对表的操作

    创建表 简单的方式 CREATE TABLE person ( number INT(11), name VARCHAR(255), birthday DATE ); 或者是 CREATE TABLE ...

  8. Java异常处理机制及两种异常的区别

    java异常处理机制主要依赖于try,catch,finally,throw,throws五个关键字.   try 关键字后紧跟一个花括号括起来的代码块,简称try块.同理:下面的也被称为相应的块. ...

  9. IO流--File--properties

    package com.songyan.properties; /** * properties * 是hashtable的子类具备map集合的特点 * 里面存储的键值对都是String而且不需要指定 ...

  10. 搭建SSH框架–使用篇

    创建如下包: action用于响应请求 service则是提供请求的操作 dao用于操作数据库 entity用于映射数据库表 打开DB Browser –> personalCD(创建篇的数据库 ...