【MongoDB】嵌套数组查询方案
From:http://stackoverflow.com/questions/12629692/querying-an-array-of-arrays-in-mongodb
数据
db.multiArr.insert({"ID" : "fruit1","Keys" : [["apple", "carrot", "banana"]]})
db.multiArr.insert({"ID" : "fruit2","Keys" : [["apple", "orange", "banana"]]})
db.multiArr.find({'Keys':{$elemMatch:{$elemMatch:{$in:['carrot']}}}})
{ "_id" : ObjectId("506555212aeb79b5f7374cbf"), "ID" : "fruit1", "Keys" : [ [ "apple", "carrot", "banana" ] ] }
db.multiArr.find({'Keys':{$elemMatch:{$elemMatch:{$in:['banana']}}}})
{ "_id" : ObjectId("506555212aeb79b5f7374cbf"), "ID" : "fruit1", "Keys" : [ [ "apple", "carrot", "banana" ] ] }
{ "_id" : ObjectId("5065587e2aeb79b5f7374cc0"), "ID" : "fruit2", "Keys" : [ [ "apple", "orange", "banana" ] ] }
查询语句:
Interesting question, This will do the trick
db.multiArr.find({'Keys':{$elemMatch:{$elemMatch:{$in:['carrot']}}}})
$elemMatch used to check if an element in an array matches the specified match expression. so nested $elemMatch will go deeper into nested arrays
补充:
http://stackoverflow.com/questions/17360423/getting-a-dictionary-inside-a-list-by-key-in-mongodb-mongoengine
【MongoDB】嵌套数组查询方案的更多相关文章
- mongodb 数组查询
转发自:https://blog.csdn.net/leshami/article/details/55049891 一.演示环境及数据> db.version() 3.2.11 > db ...
- mongodb 更新嵌套数组的值
概要 本文主要讲述在 mongodb 中,怎么更新嵌套数组的值. 使用$更新数组 基本语法 { "<array>.$" : value } 可以用于:update, ...
- Mysql or Mongodb LBS快速实现方案
http://www.wubiao.info/470 前两篇文章: 查找附近的xxx 球面距离以及Geohash方案探讨 (http://www.wubiao.info/372) 微信.陌陌 架构方案 ...
- MongoDB中数组类型相关的操作
概述 在MongoDB的模式中,我们经常将一些数据存储到数组类型中,即我们常见的嵌套模式设计的一种实现方式.数组的这种设计实现方式在关系数据库中是没有或者说不常见的.所以,通过本文我们来梳理一下Mon ...
- mongodb的高级查询
db的帮助文档 输入:db.help(); db.AddUser(username,password[, readOnly=false]) 添加用户 db.auth(usrename,passwor ...
- mongodb 高级聚合查询
mongodb高级聚合查询 在工作中会经常遇到一些mongodb的聚合操作,特此总结下.mongo存储的可以是复杂类型,比如数组.对象等mysql不善于处理的文档型结构,并且聚合的操作也比mysq ...
- .NET 云原生架构师训练营(模块二 基础巩固 MongoDB 写入和查询)--学习笔记
2.5.3 MongoDB -- 写入和查询 写入 查询 查找操作符 逻辑操作符 其他 嵌套对象 数组 游标方法 写入 https://docs.mongodb.com/manual/tutorial ...
- MongoDB 覆盖索引查询
MongoDB 覆盖索引查询 官方的MongoDB的文档中说明,覆盖查询是以下的查询: 所有的查询字段是索引的一部分 所有的查询返回字段在同一个索引中 由于所有出现在查询中的字段是索引的一部分, Mo ...
- Mongodb操作之查询(循序渐进对比SQL语句)
工具推荐:Robomongo,可自行百度寻找下载源,个人比较推荐这个工具,相比较mongoVUE则更加灵活. 集合简单查询方法 mongodb语法:db.collection.find() //co ...
随机推荐
- 02-maven常用命令,以及使用命令创建目录
maven常用命令 mvn -v 查看maven版本 compile 编译 test 测试 package 打包 clean 删除target install 安装jar包到本地仓库中. mave ...
- LINUX下动态链接库的使用-dlopen dlsym dlclose dlerror
本定义 功能:打开一个动态链接库 包含头文件: #include <dlfcn.h> 函数定义: void * dlopen( const char * pathname, int mod ...
- 转:发一个自己用过的makefile .
#gcc test.cpp -L. -Wl,-Bdynamic -ltestlib -Wl,-Bstatic -ltestlib -Wl,-Bdynamic #make clean; make in ...
- C# 通过form表单下载文本文件
public void DownLoadConfigFile(string name) { //获取文件字符串内容 var data = _service.ReadFileStr(_configure ...
- Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
setup slave from backup i got error Got fatal error 1236 from master when reading data from binary l ...
- MySQL-LAST_INSERT_ID();使用注意事项
第一.查询和插入所使用的Connection对象必须是同一个才可以,否则返回值是不可预料的. mysql> SELECT LAST_INSERT_ID(); -> 100 使 用这函数向一 ...
- Eclipse怎样连接并打开oracle等数据库?
http://jingyan.baidu.com/article/a501d80cea3ed4ec630f5e2f.html
- 完善String类([]、 +、 += 运算符重载)、>>和<<运算符重载
在前面文章中使用过几次String类的例子,现在多重载几个运算符,更加完善一下,并且重载流类运算符. []运算符重载 +运算符重载 +=运算符重载 <<运算符重载 >>运算符重 ...
- atitit。win7 win8 win9 win10 win11 新特性总结与战略规划
atitit.win7 win8 win9 win10 win11 新特性总结与战略规划 1. win7 1 1.1. 发布时间 2009年10月22日 1 1.2. 稳定性大幅提升,很少蓝屏死机 ...
- NYOJ 467 中缀式变后缀式
做了表达式求值那道题之后做的 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 人们的日常习惯是把算术表达式写成中缀式,但对于机器来说更"习惯于"后 ...