2016-12-13 56 views
1

的模式不爲空的我的文檔查找項目是這樣的:與數組項MongoDB中

history: { type: [Object] } 

我想找到那些在數組中的第15點中的項目的所有文件。

我希望將工作的查詢是:

db.getCollection('teams').find({'history.15': {$exists: true}}) 

但如果history.15爲null,它仍然會返回文檔這不是我想要的。 所以簡單的辦法應該這樣做:

db.getCollection('teams').find({'history.15': {$exists: true, $ne: null}}) 

但這並不返回任何對象(也有在我的數據庫有非空的15項數組對象)。

任何想法如何讓這個查詢工作?

更新: 這裏是不是被我的查詢找到了一個樣本文件:

{ 
    "_id" : "FR5BTtggnbxRrDqi3", 
    "history" : [ 
     null, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 34, 
      "finalLineup" : [ 
       "47oDynBoQifNyhG9u", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "6xvdipvf8PNNgaB4d" 
      ], 
      "finalSubs" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "gWtx6YZW5sPehiksC", 
       "QFWQLFyLvpzvfn9Nb", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "ad7z4NnoqMsLWyhpt", 
        "out" : "DmwbPcTpPKoPQqJe6" 
       }, 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 0, 
      "finalLineup" : [ 
       "47oDynBoQifNyhG9u", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "BaRu7TonDB8iKhzdC", 
       "DmwbPcTpPKoPQqJe6", 
       "MtZQjZqwptcY4MJXm", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "finalSubs" : [ 
       "ad7z4NnoqMsLWyhpt", 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 18, 
      "finalLineup" : [ 
       "ad7z4NnoqMsLWyhpt", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "REs5NdgicB3wYwr8F", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "QFWQLFyLvpzvfn9Nb", 
       "DmwbPcTpPKoPQqJe6", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       }, 
       { 
        "in" : "ad7z4NnoqMsLWyhpt", 
        "out" : "DmwbPcTpPKoPQqJe6" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 38, 
      "finalLineup" : [ 
       "ad7z4NnoqMsLWyhpt", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "REs5NdgicB3wYwr8F", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "QFWQLFyLvpzvfn9Nb", 
       "DmwbPcTpPKoPQqJe6", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       }, 
       { 
        "in" : "ad7z4NnoqMsLWyhpt", 
        "out" : "DmwbPcTpPKoPQqJe6" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 27, 
      "finalLineup" : [ 
       "ad7z4NnoqMsLWyhpt", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "REs5NdgicB3wYwr8F", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "QFWQLFyLvpzvfn9Nb", 
       "DmwbPcTpPKoPQqJe6", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       }, 
       { 
        "in" : "ad7z4NnoqMsLWyhpt", 
        "out" : "DmwbPcTpPKoPQqJe6" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 34, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "REs5NdgicB3wYwr8F", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "QFWQLFyLvpzvfn9Nb", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 15, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "REs5NdgicB3wYwr8F", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "QFWQLFyLvpzvfn9Nb", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 13, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "REs5NdgicB3wYwr8F", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "QFWQLFyLvpzvfn9Nb", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 34, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "REs5NdgicB3wYwr8F", 
       "QFWQLFyLvpzvfn9Nb", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "47oDynBoQifNyhG9u", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "47oDynBoQifNyhG9u" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 14, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "REs5NdgicB3wYwr8F", 
       "QFWQLFyLvpzvfn9Nb", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "47oDynBoQifNyhG9u", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "47oDynBoQifNyhG9u" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 19, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "REs5NdgicB3wYwr8F", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "QFWQLFyLvpzvfn9Nb", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 14, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "ux7HCjzSpw25JYe7r", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "QFWQLFyLvpzvfn9Nb" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "ux7HCjzSpw25JYe7r", 
        "out" : "QFWQLFyLvpzvfn9Nb" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 11, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 13, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "score" : 18, 
      "finalLineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "REs5NdgicB3wYwr8F", 
       "QFWQLFyLvpzvfn9Nb", 
       "HcPjMYdG7FcxhRuFj" 
      ], 
      "finalSubs" : [ 
       "gWtx6YZW5sPehiksC", 
       "47oDynBoQifNyhG9u", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ], 
      "autoSubs" : [ 
       { 
        "in" : "HcPjMYdG7FcxhRuFj", 
        "out" : "gWtx6YZW5sPehiksC" 
       }, 
       { 
        "in" : "REs5NdgicB3wYwr8F", 
        "out" : "47oDynBoQifNyhG9u" 
       } 
      ] 
     }, 
     { 
      "lineup" : [ 
       "DmwbPcTpPKoPQqJe6", 
       "4Csv4LDHmCku4p2d7", 
       "4cWjs7kjweQhTg5gq", 
       "BaRu7TonDB8iKhzdC", 
       "6xvdipvf8PNNgaB4d", 
       "A3vPEhAmhoMYA8iBm", 
       "AMDWHF8tkBLvGPwQx", 
       "MtZQjZqwptcY4MJXm", 
       "47oDynBoQifNyhG9u", 
       "QFWQLFyLvpzvfn9Nb", 
       "gWtx6YZW5sPehiksC" 
      ], 
      "subs" : [ 
       "HcPjMYdG7FcxhRuFj", 
       "REs5NdgicB3wYwr8F", 
       "ad7z4NnoqMsLWyhpt", 
       "ux7HCjzSpw25JYe7r" 
      ] 
     } 
    ] 
} 
+0

似乎是爲我工作。有沒有一種方法可以添加用於測試的示例數據?只是一個基於零的索引。 – Veeram

+0

這也適用於我。我猜想問題是'history.15'需要'history.14'。 – therealrootuser

+0

我已經添加了一個應該通過測試的示例文檔,與索引一起玩並不適合我。 –

回答

1

因此簡化回答了一下,說我們的一個數組a數據的3個不同位:

> db.test.find() 
{ "_id" : ObjectId("585145ee8b5e4bf7a33373ee"), "a" : [ { "i" : 0 }, { "i" : 1 } ] } 
{ "_id" : ObjectId("585145f68b5e4bf7a33373ef"), "a" : [ { "i" : 0 }, { "i" : 1 }, null ] } 
{ "_id" : ObjectId("585146038b5e4bf7a33373f0"), "a" : [ { "i" : 0 }, { "i" : 1 }, { "i" : 2 } ] } 

爲了簡單起見,在這個例子中,我們將檢查2的指數,我們可以做到這一點使用聚合框架:

var index = 2; 

db.test.aggregate([ 
    { $project: { indexValue: { $arrayElemAt: [ '$a', index ] } } }, 
    { $match: { 'indexValue' : { $ne: null } } } 
]) 

這一操作將輸出以下內容:

{ "_id" : ObjectId("585146038b5e4bf7a33373f0"), "indexValue" : { "i" : 2 } } 

符合你的標準,但如果你

db.test.find({ 'a.2' : { $ne: null } }) 

它不符合的文件,猜測這是事做訪問古怪足夠數組的索引?

反正匹配null,沒有現有文檔的更多信息,請參見 - https://docs.mongodb.com/manual/tutorial/query-for-null-fields/#equality-filter