MongoDB【条件查询】 - 比较的条件

阅读前提: 代码的背景是本ID其他的博文: ip库的查询

其格式如下:

begin          end               省                   市

18533376,18534399,内蒙古自治区,呼伦贝尔市

简单的代码:

public static IpLocation getLocation(long iplong) {

		IpLocation iplocation = new IpLocation();

		// 获取表的句柄
		DBCollection collection = null;
		// 封装查询条件
		BasicDBObject basicDBObject = null;

		try {
			collection = db.getCollection(Constant.ipBase);
			basicDBObject = new BasicDBObject();

			// begin <= iplong <= end
			basicDBObject.put("begin", new BasicDBObject("$lte", iplong));
			basicDBObject.put("end", new BasicDBObject("$gte", iplong));

			List<DBObject> dbObjectList = collection.find(basicDBObject)
					.toArray();

			iplocation.setProvince(dbObjectList.get(0).get("province")
					.toString());
			iplocation.setCity(dbObjectList.get(0).get("city").toString());

		} catch (Exception e) {
			p("查MixBoxIpBase库的过程之中出现了错误");
		}
		return iplocation;

	}

在这里

basicDBObject.put("begin", new BasicDBObject("$lte", iplong));

  lte:小于等于表示 begin 《= iplong

basicDBObject.put("end", new BasicDBObject("$gte", iplong));

  get: 大于等于表示  end 》= iplong
  
  综合起来来看就是 begin < iplong < end,  细节方面请不要出现纰漏~
时间: 2024-08-25 07:46:08

MongoDB【条件查询】 - 比较的条件的相关文章

php 条件查询和多条件查询

条件循环 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Con

sql条件为空查询全部,不为空按条件查询以及多条件筛选查询。

procedure queryLackLonOrLatTdCell(i_region_name varchar2, i_state varchar2) is begin select region_name, state from gc3_td_site_history where 1 = 1 and region_name = decode(i_region_name, null, region_name, i_region_name) and instr(decode(i_state, nu

php部分---对数据的多条件查询,批量删除

1.给多条件查询,添加条件 <h1>新闻信息查看</h1> <?php $tiaojian1=" 1=1"; $tiaojian2=" 1=1"; $title=""; //为了下面foreach中能够取到这个变量,所以在外边定义一下. $author=""; if(!empty($_POST['title'])) { $title=$_POST['title']; $tiaojian1=&quo

SM-MyBatis-13:Mybatis中多条件查询

------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 实体类 public class Book { private Integer bookID; private String bookName; private String bookAuthor; private Integer bookPrice; public Book() { } public Integer getBookID() { return this.bookID; } public vo

分页,条件查询

1 分页查询 1.1 分页核心 设计一个用于封装当前页所有分页相关的数据的PageBean对象,每次访问根据PageBean对象显示当前页面信息 1.2 分页的实现步骤 1)编写分页对象和实体对象 2)编写DAO层代码(查询总记录数和查询当前页数据) 3)编写Service层代码(封装PageBean对象) 4)编写Servlet代码(接收用户输入) 5)编写jsp页面代码(显示分页效果) 2 条件查询 2.1 条件查询的核心 根据用户的查询条件组装sql语句字符串: 注:分页查询和条件查询都是

Mongodb 条件查询

1.1 查询出所有数据的指定键(name ,age ,country) db.persons.find({},{name:1,age:1,country:1,_id:0}) 2.查询条件 2.查询条件 2.1查询出年龄在25到27岁之间的学生 db.persons.find({age: {$gte:25,$lte:27},{_id:0,age:1}) 2.2查询出所有不是韩国籍的学生的数学成绩 db.persons.find({country:{$ne:”Korea”}},{_id:0,m:1}

MongoDBTemplate多条件查询的问题

问题: 在使用Spring Data MongoDB 进行条件查询数据时,发现条件判断不起作用,结果会返回所有的数据. Criteria criteria = new Criteria(); criteria.where("shopId") .is(request.getShopId()) .and("tradeDate").gte(request.getBeginTradeDate()) .lte(request.getEndTradeDate()); List&

C# 将Access中时间段条件查询的数据添加到ListView中

C# 将Access中时间段条件查询的数据添加到ListView中 一.让ListView控件显示表头的方法 在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Columns集合中添加表头中的文字. 二.利用代码给ListView添加Item. 首先,ListView的Item属性包括Items和SubItems.必须先实例化一个ListIteView对象.具体如下: ListViewItem listViewItem=new ListViewItem(); l

php 多条件查询 例子

<hl>表单的多条件查询</h1> <form action="这个表.php" method="post"> <div> 请输入查询的名字:<input type="text" name="name" /> 请输入查询址性别:<input type="text" name="sex" /> <input ty

Django-rest-framework多条件查询/分页/多表Json

Django-rest-framework多条件查询/分页/多表Json django-rest-framework多条件查询需要覆写ListAPIView.get_queryset方法,代码示例: def get_queryset(self):     """     使用request.query_params实现多条件查询,也可以使用django filter ,较简单的     方法是在filter_fields中指定要过滤的字段,但只能表示等值,不灵活,灵活的方式是