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