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】嵌套数组查询方案的更多相关文章

  1. mongodb 数组查询

    转发自:https://blog.csdn.net/leshami/article/details/55049891 一.演示环境及数据> db.version() 3.2.11 > db ...

  2. mongodb 更新嵌套数组的值

    概要 本文主要讲述在 mongodb 中,怎么更新嵌套数组的值. 使用$更新数组 基本语法  { "<array>.$" : value } 可以用于:update, ...

  3. Mysql or Mongodb LBS快速实现方案

    http://www.wubiao.info/470 前两篇文章: 查找附近的xxx 球面距离以及Geohash方案探讨 (http://www.wubiao.info/372) 微信.陌陌 架构方案 ...

  4. MongoDB中数组类型相关的操作

    概述 在MongoDB的模式中,我们经常将一些数据存储到数组类型中,即我们常见的嵌套模式设计的一种实现方式.数组的这种设计实现方式在关系数据库中是没有或者说不常见的.所以,通过本文我们来梳理一下Mon ...

  5. mongodb的高级查询

    db的帮助文档 输入:db.help(); db.AddUser(username,password[, readOnly=false])  添加用户 db.auth(usrename,passwor ...

  6. mongodb 高级聚合查询

    mongodb高级聚合查询   在工作中会经常遇到一些mongodb的聚合操作,特此总结下.mongo存储的可以是复杂类型,比如数组.对象等mysql不善于处理的文档型结构,并且聚合的操作也比mysq ...

  7. .NET 云原生架构师训练营(模块二 基础巩固 MongoDB 写入和查询)--学习笔记

    2.5.3 MongoDB -- 写入和查询 写入 查询 查找操作符 逻辑操作符 其他 嵌套对象 数组 游标方法 写入 https://docs.mongodb.com/manual/tutorial ...

  8. MongoDB 覆盖索引查询

    MongoDB 覆盖索引查询 官方的MongoDB的文档中说明,覆盖查询是以下的查询: 所有的查询字段是索引的一部分 所有的查询返回字段在同一个索引中 由于所有出现在查询中的字段是索引的一部分, Mo ...

  9. Mongodb操作之查询(循序渐进对比SQL语句)

    工具推荐:Robomongo,可自行百度寻找下载源,个人比较推荐这个工具,相比较mongoVUE则更加灵活. 集合简单查询方法 mongodb语法:db.collection.find()  //co ...

随机推荐

  1. 〖Android〗查找Android中的/system/lib中增加的lib文件是否在apk文件中

    #!/bin/bash - #=============================================================================== # # F ...

  2. Android 混淆打包不混淆第三方jar包

    项目由于要公布,所以要混淆打包. 混淆打包流程: 1.在proguard-project.txt文件里加入不须要混淆的类和第三方的jar包   这个是保持自己包中不须要混淆的类,假设有些类调用了jni ...

  3. css background-position结合disaply:inline-block使用

    $(".icon-a").on('click', function (e) { if ($(this).next().css('display') == "none&qu ...

  4. html <br/>引起的”血案“

    图片一: 图片二: 图片三: 图片四:

  5. php实现二维数组排序array_multisort($ages, SORT_DESC, $home)函数

    1.sql查询排序参数是order by,那么php进行排序呢 可以参考array_multisrot函数 //php进行二维数组排序 -xzz1009 foreach($home as $home) ...

  6. Ubuntu和windows文件共享问题

    ubuntu访问windows共享文件夹(ubuntu桌面系统):          最简单的方法,随便打开一个文件夹,按Ctrl+L,然后地址栏敲smb://xxx.xxx.xxx.xxx(wind ...

  7. Windows7下搭建Android开发环境

    以后工作中要用到android开发,所以想搭建好开发环境,笔记本装的是win7 准备文件: 1 下载Android SDK http://code.google.com/android/downloa ...

  8. 常用音频软件:Wavesufer

    作者:桂. 时间:2017-06-02  10:23:39 链接:http://www.cnblogs.com/xingshansi/p/6932408.html 前言 只列举两个自己用过的(wave ...

  9. [转]如何为图片添加热点链接?(map + area)

    原文地址:https://www.cnblogs.com/jf-67/p/8135004.html 所谓图片热点链接就是为图片指定一个或多个区域以实现点击跳转到指定的页面.简单来说就是点击某一区域就能 ...

  10. 信号处理函数(2)-sigismember()

    定义: int sigismember(const sigset_t *set,int signum);   表头文件: #include<signal.h>   说明: sigismem ...