0

I struggle with a find query.

I have two documents in a mongodb grid collection:

{
    "_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"
}

Now I want to make a query which retreive the document where "filename" = "test.xml" and the tag "vision_id" = "1282".

Now I made the search query like this:

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

If I run this I don't get a result:

When I remove the line array("data" => array("vision_id" => "1282")), then I get the last document. (As I predicted).

Could anybody give me a push to the right way, to search also within the data array?

Kind Regards,

Arjan Kroon

1 Answer 1

1

I found the solution.

$query = 
    array('$and' => 
        array(
            array("filename" => "text.xml"),
            array("data.vision_id" => "1282"),
        ),
    );
Sign up to request clarification or add additional context in comments.

1 Comment

sorry no idea in mongodb

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.