【问题标题】:mongodb query find in arraymongodb查询在数组中查找
【发布时间】:2015-07-29 11:27:23
【问题描述】:

我很难找到查询。

我在 mongodb 网格集合中有两个文档:

{
    "_id" : ObjectId("55b8ac2c1a80142e7f7b23cd"),
    "metadata" : {
        "filename" : "test2.xml",
        "contentType" : "application/xml"
    },
    "data" : {
        "type_file" : "test",
        "vision_id" : "6987"
    },
    "filename" : "test2.xml",
    "uploadDate" : ISODate("2015-07-29T10:34:20.991Z"),
    "length" : NumberLong(9582),
    "chunkSize" : NumberLong(261120),
    "md5" : "ea40283994f451b357555e53d186ed1e"
}
{
    "_id" : ObjectId("55b8ac2c1a80142e7f7b23cd"),
    "metadata" : {
        "filename" : "test.xml",
        "contentType" : "application/xml"
    },
    "data" : {
        "type_file" : "test",
        "vision_id" : "1282"
    },
    "filename" : "test.xml",
    "uploadDate" : ISODate("2015-07-29T10:34:20.991Z"),
    "length" : NumberLong(9582),
    "chunkSize" : NumberLong(261120),
    "md5" : "ea40283994f451b357555e53d186ed1e"
}

现在我想做一个查询来检索“filename”=“test.xml”和标签“vision_id”=“1282”的文档。

现在我做了这样的搜索查询:

$query = 
    array('$and' => 
        array(
            array("filename" => "text.xml),
            array("data" => array("vision_id" => "1282")),
        ),
    );
$cursor = $gridFS->find($query)

如果我运行它,我不会得到结果:

当我删除array("data" => array("vision_id" => "1282")) 行时,我得到了最后一个文档。 (如我所料)。

谁能给我一个正确的方法,在数据数组中搜索?

亲切的问候,

阿扬·克朗

【问题讨论】:

    标签: mongodb mongodb-query


    【解决方案1】:

    我找到了解决办法。

    $query = 
        array('$and' => 
            array(
                array("filename" => "text.xml"),
                array("data.vision_id" => "1282"),
            ),
        );
    

    【讨论】:

    • 抱歉在 mongodb 中不知道
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 2019-04-05
    相关资源
    最近更新 更多