I have a collection in MongoDB called shop
shop{
"_id" : "523c1e",
"address" : "100, University Road",
"city" : "xyz",
"contact_name" : "John",
"deals" : [
{
"deal_id" : "524913",
"deal_type" : "Sale",
"deal_description" : "Very good deal",
"start_date" : "2013-09-12",
"end_date" : "2013-09-31"
},
{
"deal_id" : "52491abf6",
"deal_type" : "Sale",
"deal_description" : "Buy 2 jeans, get one free",
"start_date" : "2013-09-20",
"end_date" : "2013-10-31"
}
],
}
I want to find deals which is now running(for current date '2013-10-01') and _id="523c1e" using mongodb and php,
So I will get,
{
"deal_id" : "52491abf6",
"deal_type" : "Sale",
"deal_description" : "Buy 2 jeans, get one free",
"start_date" : "2013-09-20",
"end_date" : "2013-10-31"
}
please help me to right this query,
I am trying this one but not give any output
<?php
date_default_timezone_set('Asia/Kolkata');
$date=date('Y-m-d');
$pro_id='523c1e';
$cursor = $collection->find(array("_id" => "$pro_id",$date => array('$gt' => 'deals.start_date','$lte' => 'deals.end_date')),array("deals" => 1));
foreach($cursor as $document)
{
echo json_encode(array('posts'=>$document));
}
?>
Please help me...