包含许多具有以下结构的文档的Mongodb集合
{
"_id": ObjectId("52f4a5ed07b0f7106a9d5e4c"),
"FM_ID":"1253",
"passwd": ".aDoSkljf_h+6589q76w3rJK",
"Area": {
"0": {
"X": "53543500",
"Y": "14031500",
"images": {
"0": {
"ImgId": ObjectId("52f4a5a107b0f7106a9d1a84"),
"ImageType": NumberInt(15)
},
"1": {
"ImgId": ObjectId("52f4a5a107b0f7106a9d1a87"),
"ImageType": NumberInt(2)
}
}
},
"1": {
"X": "53543500",
"Y": "14094572",
"images": {
"0": {
"ImgId": ObjectId("52f4a5a107b0f7106a9d1aa8"),
"ImageType": NumberInt(15)
},
"1": {
"ImgId": ObjectId("52f4a5a107b0f7106a9d1aab"),
"ImageType": NumberInt(2)
},
"2": {
"ImgId": ObjectId("52f4a5a107b0f7106a9d1aae"),
"ImageType": NumberInt(0)
}
}
},
"2": {
"X": "53480464",
"Y": "14031500",
"images": {
"0": {
"ImgId": ObjectId("52f4a5a107b0f7106a9d1acc"),
"ImageType": NumberInt(15)
}
}
}
想要仅过滤ImageType = 2集合
andQueryObj.add(new BasicDBObject("Area", new BasicDBObject("$elemMatch", new BasicDBObject("images", new BasicDBObject("$elemMatch", new BasicDBObject("ImageType", "2"))))));
此查询不起作用。如何过滤基于内部对象元素值的数据..?
答案 0 :(得分:0)
1)我看到的一个问题是你打字:
BasicDBObject("imageType", "2")
我认为应该是:
BasicDBObject("ImageType", "2")
即。 ImageType
应该大写。
2)也试试这个。
BasicDBObject("ImageType", new Integer("2"))
我的意思是,你的ImageType是MongoDB中的NumberInt,所以你应该
在Java中尝试Integer。目前您正在寻找字符串“2”和
不适用于整数2.