我有一个mongodb集合"结果"使用
等数据{ "_id" : {
"user" : "Howard",
"friend" : "Sita"
},
"value" : {
"mutualFriend" :[ "Hanks", "Bikash", "Shyam", "Bakshi" ]
}
}
{ "_id" : {
"user" : "Shiva",
"friend" : "Tom"
},
"value" : {
"friendList" :[ "Hanks", " Tom", " Karma", " Hari", " Dinesh" ]
}
}
{ "_id" : {
"user" : "Hari",
"friend" : "Shiva"
},
"value" : {
"mutualFriend" :[ "Tom", "Karma", "Dinesh" ]
}
}
现在,我想查询具有value.mutualFriend
的整个文档。我怎样才能得到结果?
预期输出
{ "_id" : {
"user" : "Howard",
"friend" : "Sita"
},
"value" : {
"mutualFriend" :[ "Hanks", "Bikash", "Shyam", "Bakshi" ]
}
}
{ "_id" : {
"user" : "Hari",
"friend" : "Shiva"
},
"value" : {
"mutualFriend" :[ "Tom", "Karma", "Dinesh" ]
}
}
我在MongoDB集合中有大量文档,包含value.friendList
和value.mutualFriend
,然后我只想找到value.mutualFriend
答案 0 :(得分:1)
getWeeklyOpenPositions(boolean flagCurrently){
String query="SELECT * FROM Report WHERE Open_TS BETWEEN '20160101' AND '20161230'";
if(flagCurrently)
{
query=query+ " AND close_TS>NOW()";
}
}
它只是确保第0个元素存在。您可以在各种数组长度上自定义查询。