mongoDB使用java获取对象和部分数组

时间:2014-07-09 10:48:27

标签: arrays mongodb

我的mongo对象将是这样的

{
    "colID" : "1",
    "title" : "title",
    "desciption : "description",
    "array" : [
        { "identifier" : "1", "title" : "test1"},
        { "identifier" : "2", "title" : "test2"},
    ]
}

输入为:colID为1,标识符为2.现在我想得到以下响应

{
    "colID" : "1",
    "title" : "title",
    "desciption : "description",
    "array" : [
        { "identifier" : "2", "title" : "test2"}
    ]
}

请帮助我对mongoDB很新。提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用$ elemMatch运算符。

查看MongoDB文档:

http://docs.mongodb.org/manual/reference/operator/projection/elemMatch/