MongoDB操作符中的$elemMatch问题
但 db.getCollection(Persion).find({relatives:{$elemMatch:{name: 赵四,一瞬间我陷入了迷茫, relationship: 0}}}) 此时可以得到结果。
name : 赵小明。
我们需要用到我们今天的主角$elemMatch , relatives : [ { name : 赵刚, age : 16。
... } } } If you specify only a singlecondition in the $elemMatch expression, relationship: 1}}}) 结果为空集 结语 此操作符和索引也有一些不得不说的事, relationship : 1 } ] } 我们执行查询 db.getCollection(Persion).find({relatives.name: 赵刚,每个查询条件仅需有数组中的一项满足条件即可。
query2, relatives.relationship: 1}) 此时会得到结果吗? 最开始我想当然的以为是不会出现结果的,之后我会专门总结一篇有关MongoDB索引相关的博客 等不及的看官可以自行百度Google一下,今天就不在这里细说了,更多相关MongoDB操作符之$elemMatch内容请搜索聚合云库文库以前的文章或继续浏览下面的相关文章希望大家以后多多支持聚合云库文库! 原文链接:https://www.cnblogs.com/SwordArt/p/12588365.html , 那如果我想达到后面的效果要怎么做呢? 解决 此时, 什么, relatives.relationship: 0}) 此次可得到一条结果 通过上述两次查询基本可以排除二级字段的影响 那就是数组的原因了,继续进行不同的查询 db.getCollection(Persion).find({relatives.name: 赵刚, 总结 到此这篇关于MongoDB操作符之$elemMatch的文章就介绍到这了, used_name : [ 赵明, 如果MongoDB 数据库集合中仅存在一条记录 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 { _id : ObjectId(5e6b4ef546b5f44e5c5b276d),Mongo的查询结果不是必须都满足所有条件的吗? 分析 不信邪的我又尝试了喜闻乐见的小白查询 db.getCollection(Persion).find({name: 赵小明, age: 18}) 这次结果为空, used_name : [ 赵明,它的官方定义是这样的: The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria. { field: { $elemMatch: { query1,对于数组字段, name : 赵小明,那具体是为什么呢? 将数据还原为最初的格式, gender : 0,这才是我熟悉的Mongo嘛? 那这两次查询有啥区别呢?不同有两点 是否为二级字段 是否为数组 那我们将数据改为 1 2 3 4 5 6 7 8 9 10 11 12 13 14 { _id : ObjectId(5e6b4ef546b5f44e5c5b276d), 赵小朋 ], relative : { name : 赵刚, 赵小朋 ],嗯。
而不是数组中必须存在一项满足所有查询条件, relatives.relationship: 1}) 此次结果为空集 接下来尝试查询 db.getCollection(Persion).find({relatives.name: 赵刚,但结果往往与期望背道而驰, relationship : 0 }, gender : 0, you do not need to use $elemMatch. You cannot specify a $where expression in an $elemMatch. You cannot specify a $text query expression in an $elemMatch. 那上边的查询我们可以改成 db.getCollection(Persion).find({relatives:{$elemMatch:{name: 赵四, relationship : 0 } } 继续执行查询 db.getCollection(Persion).find({relatives.name: 赵刚。
relatives.relationship: 2}) 此次结果为空集 那我们可以得到结论, { name : 秀英, age : 16,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/sql/mogodb/10341.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
MongoDB开启权限认证的方法
时间:2021-01-09
-
window下安装配置mongodb的教
时间:2021-01-09
-
浅谈MySQL和MariaDB区别(mar
时间:2021-01-09
-
MongoDB自动删除过期数据的
时间:2021-01-07
-
Windows 10下安装最新版Mon
时间:2021-01-07
-
MongoDB使用mongoexport和mong
时间:2021-01-07
-
MongoDb的"not master and sla
时间:2021-01-07
-
MongoDB特点与体系结构等简
时间:2021-01-07
热门文章
-
MongoDB Atlas现支持多云数据库集群
时间:2020-12-24
-
MongoDB自动删除过期数据的方法(TTL索引)
时间:2021-01-07
-
将MongoDB加入到Windows的本地服务项的方法
时间:2020-12-24
-
MongoDB特点与体系结构等简介
时间:2021-01-07
-
浅谈MySQL和MariaDB区别(mariadb和mysql的性能比
时间:2021-01-09
-
Windows 10下安装最新版MongoDB的完整步骤
时间:2021-01-07
-
MongoDB使用mongoexport和mongoimport命令,批量导
时间:2021-01-07
-
如何使用Docker安装一个MongoDB最新版
时间:2020-12-28
-
MongoDB创建一个索引而性能提升1000倍示例
时间:2021-01-07
-
MongoDB学习笔记(六) MongoDB索引用法和效率
时间:2020-12-24
