I’m scratching my head for several hours and can’t figure out how can I query the following document by price.amount
{
"_id" : ObjectId("4f148bb56858c43428f0666b"),
"Date" : new Date("Sat, 13 Sep 2014 00:42:29 GMT +04:00"),
"Items" : [{
"ProductId" : ObjectId("4f14873f6858c42ce82968e6"),
"Quantity" : 5,
"Price" : {
"Amount" : "4929",
"Currency" : "USD"
}
}, }, {
"ProductId" : ObjectId("4f14873f6858c42ce829692b"),
"Quantity" : 10,
"Price" : {
"Amount" : "140",
"Currency" : "USD"
}
}],
"CustomerId" : ObjectId("4f1487f16858c419c04ec2e2")
}
I want to select all objects which has min 1 Price item with amount > 10 for example.
Thanks
Your “Amount” field is of type string (which I’m assuming is wrong). As such you need to compare with a string value as is shown in my example query. Obviously this will produce rather unpredictable results if you actually want to compare integers. If so, convert both the “Amount” field and the $gt value in your query to numbers.