I'm trying to do a query(In MongoDB) in array("availability") that will return a only hotel that have the element("available") equals 1 and between the dates inside the availability.
But the query return all hotels when the correct return is "Mercato Hotel"
Query that i have used without success:
{city: "Boston", availability: { $elemMatch: {availability: 1, date: {$gte: ISODate("2015-05-02T00:00:00.000+0000")}, date: {$lte: ISODate("2015-05-04T00:00:00.000+0000")}}}}
Json in MongoDb:
{
"_id" : ObjectId("55b302ee8debdf1a908cdc85"),
"city" : "Boston",
"hotel" : "Mercatto Hotel",
"availability" : [
{
"date" : ISODate("2015-05-01T00:00:00.000+0000"),
"available" : NumberInt(0)
},
{
"date" : ISODate("2015-05-02T00:00:00.000+0000"),
"available" : NumberInt(0)
},
{
"date" : ISODate("2015-05-03T00:00:00.000+0000"),
"available" : NumberInt(0)
},
{
"date" : ISODate("2015-05-04T00:00:00.000+0000"),
"available" : NumberInt(1)
}
]
}
{
"_id" : ObjectId("55b302ee8debdf1a908cdc89"),
"city" : "Boston",
"hotel" : "Hostel Villa",
"availability" : [
{
"date" : ISODate("2015-05-01T00:00:00.000+0000"),
"available" : NumberInt(1)
},
{
"date" : ISODate("2015-05-02T00:00:00.000+0000"),
"available" : NumberInt(0)
},
{
"date" : ISODate("2015-05-03T00:00:00.000+0000"),
"available" : NumberInt(0)
},
{
"date: ISODate("2015-05-04T00:00:00.000+0000"),
"available" : NumberInt(0)
}
]
}
Someone can help me?
Thanks...