doxqszx09742 2016-08-04 19:47
浏览 66

PHP MongoDB查询特定的数组条目

MongoDB Document structure is as follows:

{
    "_id" : ObjectId("5755dbcf725c4a1394f5d64f"),
    "date_prices" : [ 
        {
            "d" : ISODate("2016-06-06T20:23:32.184Z"),
            "p" : 895000
        }, 
        {
            "d" : ISODate("2016-06-10T05:49:25.362Z"),
            "p" : 895000
        }, 
        {
            "d" : ISODate("2016-06-17T22:58:14.002Z"),
            "p" : 895000
        }, 
        {
            "d" : ISODate("2016-06-19T19:46:35.826Z"),
            "p" : 895000
        }
    ],
    "id" : "6315590",
}

We need to find all documents where the first entry of date_prices array (index 0 thus) has a date greater than a specific value and where the last array entry (index 3 in the example above) has a date lower than a specific value.

Any hint on how to do this in PHP would be greatly appreciated.

Note: date_prices array typically contains hundreds of entries.

Many thanks, Tom

UPDATE:

After some further searching I came up with the following request (PHP) but it isn't working - any hint would be appreciated, thx!

array(1) { ["date_prices.0.d"]=> array(1) { ["$gte"]=> string(10) "2011-08-01" } }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 操作系统相关算法中while();的含义
    • ¥15 CNVcaller安装后无法找到文件
    • ¥15 visual studio2022中文乱码无法解决
    • ¥15 关于华为5g模块mh5000-31接线问题
    • ¥15 keil L6007U报错
    • ¥15 webapi 发布到iis后无法访问
    • ¥15 初学者如何快速上手学习stm32?
    • ¥15 如何自动更换布娃娃图片上的衣服
    • ¥15 心理学eprime编程
    • ¥15 arduino esp8266开发