mongodb数据查询(进阶篇)

mongo同步-spring batch(8)的mongo读写组件使用 Spring Batch的读组件(`ItemReader`),处理组件(`ItemProcessor`),写组件(`ItemWriter`)支持丰富的数据类型,其中`MongoItemReader`及`MongoItemWriter`是针对mongo的读写组件,用户可以直接使用,进行`Mongodb`的数据读写操作 阅读详情

之前说了一些mongodb的最基本操作,但是就前面所学的还是应付不了常规的开发,例如模糊查询、范围查询、in查询、or查询等前面说的命令就不能实现这些功能,这次分享的东西比上次稍微复杂了点,但是只要认真学习下也能很好掌握。

1.查询时屏蔽某些字段

在某些查询中由于数据表的字段比较多,但是可能只需要用到其中几个字段,这时就可以使用这个功能了,如下所示:

find后面的花括号可以写条件,后面的花括号就是字段的一些限制了,上面的_id为0说明_id这个字段不要,如果为1表示要查询出该字段


2.范围查询

这一类的查询就类似关系型数据库的>,<,between....and等的使用,在mongodb中>用$gt,小于用$lt,大于等于是$gte,小于等于用$lte表示,下面这个查询用了取出年龄在16至20之间的学生信息



3.in/not in条件查询

对于mongodb类似in这样的关键字都有$修饰,来看看下面的查询,马上就知道in的使用了

如果是not in查询,也很简单如下所示:


4.ne查询

这种查询类似!=,但是mongodb没有提供类似eq这样的操作

这个语句查询的是name不为tom的学生信息


5.正则表达式查询

这种查询类似以前的模糊查询,也就是说查询条件是一个正则表达式

这个语句的意思是查询name以y结尾的学生信息,下面这个查询的是名字含有a的学生信息

mongodb的查询是不是很简单呢


6.or查询

这个查询的使用率就不多说了

这个是一个综合查询,意思是查询age为16,17或者name为tom的学生信息


下次要分享的内容是mongodb的聚合函数的使用。

Spring Boot中使用MongoDB聚合管道进行数据查询操作 在上面的代码中,我们使用Aggregation类创建了一个聚合管道查询,并使用$facet操作符进行分组。在上面的代码中,我们使用Aggregation类创建了一个聚合管道查询,并使用$lookup操作符将User集合中的"departmentId"字段与Department集合中的"_id"字段进行关联查询。在上面的代码中,我们使用Aggregation类创建了一个聚合管道查询,并使用$group操作符按照"age"字段进行分组,并使用count操作符计算每个年龄组的文档数量。操作符进行分组操作。 阅读详情

相关推荐

使用kotlin语言连接mongodb服务进行添加数据操作

使用kotlin语言连接mongodb服务进行添加数据操作使用kotlin语言连接mongodb服务进行添加数据操作

mongodb多个条件查询in,日期查询等常用实例

in db.inventory.find( { qty: { $in: [ 5, 15 ] } } ) 日期查询 db.books.find({"time":{"$gt":ISODate("2019-06-29T00:00:00Z")}},{"time":1}) 查询时间大于6-29,结果显示一列 db.getCollection('books').find({"pub...

weixin_30593443的博客 691

《IC验证必看|IC验证的全流程概览(从DUT到回归交付)》

本文系统介绍了IC验证的全流程,从理解设计需求到最终交付验证结果。主要内容包括:1)深入理解DUT的功能和接口;2)制定详细的测试计划(Testplan);3)搭建UVM验证平台;4)执行定向和随机测试并进行回归;5)分析功能、代码和断言覆盖率;6)交付完整的验证报告。文章强调验证是一个闭环过程,特别指出新手容易忽视测试计划和覆盖率分析这两个关键环节,导致验证不充分。文末还提出思考题,引导读者反思验证计划的制定方法。

m0_46663240的博客 1274

MongoDB数据查询详解

查询全部 ​ db.infos.find(); db.infos.find({"url":"www.baidu.com"}); id不要显示出来 db.infos.find({"url":"www.baidu.com"},{"_id":0}); 关系运算 大于 $gt 小于 $lt 大于等于 $gte 小于等于 $lte 不等于 $ne 准备...

weixin_34235105的博客 363

什么是无人机巡检?如何实现无人机自动巡检?

复亚智能的无人机自动巡检系统通过高度自动化的技术,实现了无人机的高效巡检作业。无人机自动机场支持无人机的自动起降和电池更换,自动飞行算法确保无人机在复杂环境中的精准飞行和拍摄,而云端识别诊断和AI感知算法平台则实现图像的实时传输和智能分析。复亚智能,作为无人机技术的创新者和推动者,致力于开发先进的无人机自动巡检解决方案,助力各行各业实现智能化、自动化的巡检工作,引领智能巡检的未来。利用人工智能和机器学习算法,无人机可以被训练来识别特定的模式和异常,如结构损坏、热泄漏等,从而提高巡检的准确性和效率。

foiadrone的博客 2852

Tlsr8258开发-程序烧写

开源一小步,进步一大步

自学嵌入式 1786

MongoDb 命令查询所有数据库列表

MongoDb 命令查询所有数据库列表

tj的博客 2849

傅里叶光学(1)

傅里叶光学,可以看作是通信理论中傅里叶变换等一系列数学思想以及系统理论与光学(主要是衍射光学)相结合的产物关于傅里叶光学的应用领域,本节介绍了成像,当然事实上不可能仅限于成像,经典的还如激光散斑的一些应用,干涉计量,还有傅里叶变换光谱学等等。最后总结一下,傅里叶光学我认为可以看做一个工具,对于任意的系统,它能给出一些数学思想与物理原理进行解释和分析,找出系统的扰动和响应的关系,或者说根据扰动和响应,来研究或者设计一个系统。

m0_53607446的博客 1706

mongodb中的in和notin的查询

项目中的枚举值,有在一个范围内查询,有不在一个范围中查询。 如果在一个范围中查询可以使用 {$in:["VM","STORAGE_EFS","STORAGE"]} 如果不在一个范围中的查询可以使用 {$nin:["VM","STORAGE_EFS","STORAGE"]} 完整的sql: db.getCollection('usages').find({"tenantId":1453580696349184000,"billingItem":{$nin:["VM","STORAGE_EFS","STOR

keyboard专栏 1万+

eDP V1.4协议介绍

eDP的全称是Embedded DisplayPort嵌入式显示端口,主要应用与短距离系统内应用,例如手机、一体式台式机等。eDP V1.4b是基于DP V1.3标准制作完成,但因应用场景的不同,还是有很多区别。电压摆幅不同,eDP相对较低;eDP功耗相对较低;DP有线材和连接器的要求,eDP没有明确要求;AUX通道电路设计不同(相对DP取消了AC耦合电容和100KΩ/1MΩ的上下拉电阻):典型应用场景;

qflook的博客 4319

YOLO11改进策略【独家融合改进】| EfficientViMBlock + LGAG + DySample

通过学习采样来学习上采样DySample。

Limiiiing的博客 371

Presto连接mongodb实现数据查询

presto连接mongodb实现数据查询 1.安装 1.1 拉取镜像 docker pull prestosql/presto 1.2 启动容器 docker run -p 8081:8081 --name presto prestosql/presto 上述端口自定义即可。如果想让其他主机连接该容器,需要打开8081端口的防火墙,命令如下: # firewall-cmd --zone=public --add-port=8081/tcp --permanent # firewall-cmd --re

xu2439645715的博客 2756

.Net如何使用Web API实现数据交互?

数据模型代表了要交互的数据结构。例如,假设我们要创建一个简单的图书管理系统,我们可以定义一个Book类作为数据模型。set;set;set;

Code365 267

MongoDB 数据查询(经典查询命令例题合集)

数据查询 增加 persons 集合,执行 persons.json (附件)实现文档的插入,基于Library 数据库中的Media和Persons集合:load ("persons.json") 查询出所有 library 数据库中的media集合的数据 db.media.find() 查询出 persons 集合中所有数据的指定键(name,age,country) db.persons.find ( {, {_id:0,name:1,age:1,country:1}) 查询出所有 library

sjjsaaaa的博客 3456

Centos 7 Linux 离线安装单机 Kafka:下载、安装、配置、使用

本文详细介绍了在 CentOS 7 系统上离线安装单机版 Apache Kafka 的完整流程,包括环境准备(JDK 安装)、Kafka 安装包上传与解压、关键配置修改(如监听地址)、ZooKeeper 与 Kafka 服务的启动,以及 Topic 的创建、消息的生产和消费等基础操作。适用于无网络环境下的 Kafka 快速部署与学习,为后续开发或测试提供本地消息队列支持。

寒水馨 · 轻量级技术文档 · hanshuixin.org 1326

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

MongoDB数据查询和聚合分析

文章目录2. MongDB数据查询语句与聚合分析2.1 MongoDB条件查询2.1.1 数组元素的匹配查询2.1.2 模糊匹配查询2.1.3 MongoDB数据查询嵌套数组文档2.2 映射Project与过滤2.3 去除重复Distinct2.4 分组统计Group By2.4.1 MongoDB聚合分析方式2.4.2 MongoDB聚合分组统计GroupBy2.4.2.1 MongoDB聚合分...

人生就是为了樱岛麻衣的博客 856

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

MongoDB之数据查询

—引子 这次窝瓜为大家带来的是关于MongoDB之中,关于数据查询的部分。 众所周知,只要是数据库,对于查询这个功能,都是非常重要的,在这次给小伙伴们带来的,还有着一些比较零碎的知识点,希望能给初学的小伙伴一点帮助! 关系运算符详解: 运算符 含义 $gt 大于 $lt 小于 $gte 大于等于 $lte 小于等于 $ne 不等于 ktu:value 等于 ...

weixin_43754669的博客 504

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

MongoDB 各种数据查询

文章目录基本查询数据where 筛选条件指定查询显示的列(key)排序结果集分页查询显示模糊查询高级查询等值查询多条件 and 查询多条件 or 查询非查询 $nor比较符 关于数据的查询,我单独写了一篇blog。 基本查询数据 代码 含义 db.t_user.find(); 列出表中所有数据 db.t_user.findOne(); 查询集合中的第一条数据 db.t_us...

董董的^数据空间 538

MongoDB 数据查询操作

目录 MongoDB 查询操作 实例 简介 find() 以及投影操作 关系运算查询(大于、小于、等于...) 模糊查询 范围查询($in,$nin) 逻辑运算查询(或者 $or、等于 $and、非或者 $nor 以及 $not) 存在查询(存在 $exists、null 查询) 嵌套查询以及 "$all"、"$size" 取模查询($mod) "$where" 查询 ...

Wayfreem的博客 2万+

MongoDB 数据查询

数据查询 基本查询 方法find():查询 db.集合名称.find({条件文档})    方法findOne():查询,只返回第一个 db.集合名称.findOne({条件文档})    方法pretty():将结果格式化 db.集合名称.find({条件文档}).pretty()    比较运算符 ...

anbingzhong1132的博客 103

MongoDB数据查询,分页,排序

MongoDB数据查询数据准备:persons.jsonvar persons = [{ name:"jim", age:25, email:"75431457@qq.com", c:89,m:96,e:87, country:"USA", books:["JS","C++","EXTJS","MONGODB"] }, { name:"tom"

世界那么大,我想去看看! 5476

MongoDB数据查询

mongodb的条件查询返回单条数据或多条数据以及数据的格式化输出

未知的无限可能 699

MongoDB集合数据查询

(1)查询所有记录 db.userInfo.find(); 相当于:select * from userInfo (2)查询去重后数据 db.userInfo.distince("name"); 相当于:select distinct name from userInfo; (3)查询age=22的记录 db.userInfo.find({"age",22}); 相当于:select * from userInfo where age=22 (4)查询age>22的记录 db.userInfo

weixin_44759289的博客 7567

MongoDB----数据查询 聚合操作

where: 使⽤$where后⾯写⼀个函数, 返回满⾜条件的数据// 查询年龄⼤于30的学⽣。

m0_53095312的博客 2606

mongodb千万级数据查询等待问题

0011_mongodb千万级数据查询等待问题 从师兄那里拿到一个数据库有上千万条数据,由于其存储格式有些不正规,于是发现正则查询一个里面不存在的数据需要大量时间 于是通过阅读源代码注释发现可以通过设置超时指标和抛出异常的方式跳过这些不存在的数据,以节省时间效率 # 查询relay是否在traceroute中 # 导入模块 import pymongo # 连接数据库 client = pymongo.MongoClient("mongodb://127.0.0.1:27017/") db = cli

github_38008340的博客 3870

mongoDB基础篇——NoSQL特性及MongoDB数据查询

在 【MongoDB基础篇——走进非关系型数据库mongoDB】和【MongoDB应用篇——面向集合的数据库操作】中,初步介绍了非关系型数据库MongoDB的基本结构和传统关系型数据库的区别,以及数据库的增删改查操作。 本文将进一步介绍MongoDB的特点,深入了解面向集合操作的数据库增删改查。 一、MongoDB特性 结合传统关系型数据库,我们从以下四个方面再度深入认识NoSQ

Think In JAVA—Max 4785
上一篇: groovy中List集合的使用
下一篇: 第一个Grails程序
青蛙小王子
博客等级 码龄16年 239粉丝 311原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值