我的文档的架构是这样的:
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 :(得分: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