mongodb学习之:条件操作符

在前面的章节中我们已经有用到了条件操作符,这里我们再重点介绍下。MongoDB中条件操作符有:

  • (>) 大于 - $gt
  • (<) 小于 - $lt
  • (>=) 大于等于 - $gte
  • (<= ) 小于等于 - $lte
  • (==)等于 $eq
  • (!=)不等于$ne

> db.maple.find({"age":{$gt:30}})   等价与 select * from maple where age > 30

> db.maple.find({"age":{$gte:35}})  等价与select * from maple where age >=35

> db.maple.find({"age":{$lt:30}})  等价与select * from maple where age < 30

> db.maple.find({"age":{$lte:35}})  等价与select * from maple where age < =30

 

下面来介绍下type操作符:

$type操作符是基于BSON类型来检索集合中匹配的数据类型,并返回结果

MongoDB 中可以使用的类型如下表所示:

类型

数字

备注

Double

1

 

String

2

 

Object

3

 

Array

4

 

Binary data

5

 

Undefined

6

已废弃。

Object id

7

 

Boolean

8

 

Date

9

 

Null

10

 

Regular Expression

11

 

JavaScript

13

 

Symbol

14

 

JavaScript (with scope)

15

 

32-bit integer

16

 

Timestamp

17

 

64-bit integer

18

 

Min key

255

Query with -1.

Max key

127

 

使用例子如下:

> db.maple.find({"name":{$type:2}})

{ "_id" : ObjectId("5a35d6278ef76f6d57aae92c"), "name" : "zhanghongfeng_maple" }

posted @   red_leaf_412  阅读(672)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示