我有存儲在MongoDB中收集類似的一些數據:查找文檔
{"_id": 1, "category": "food", "name": "chips", "price": 1.50, "effectiveDate": ISODate("2013-03-01T07:00:00Z")}
{"_id": 2, "category": "food", "name": "chips", "price": 1.75, "effectiveDate": ISODate("2013-03-05T07:00:00Z")}
{"_id": 3, "category": "food", "name": "chips", "price": 1.90, "effectiveDate": ISODate("2013-03-10T07:00:00Z")}
{"_id": 4, "category": "beverage", "name": "pop", "price": 2.00, "effectiveDate": ISODate("2013-03-01T07:00:00Z")}
{"_id": 5, "category": "beverage", "name": "pop", "price": 2.25, "effectiveDate": ISODate("2013-03-05T07:00:00Z")}
{"_id": 6, "category": "beverage", "name": "pop", "price": 1.80, "effectiveDate": ISODate("2013-03-10T07:00:00Z")}
在MongoDB中,我將如何去寫一個查詢,都將返回一個活躍的文件在特定的日期,按類別分組?
如果我指定的2013年3月6日,我期望看到的結果:
{"_id": 2, "category": "food", "name": "chips", "price": 1.75, "effectiveDate": ISODate("2013-03-05T07:00:00Z")}
{"_id": 5, "category": "beverage", "name": "pop", "price": 2.25, "effectiveDate": ISODate("2013-03-05T07:00:00Z")}
我是新來蒙戈並一直在努力做到這一點使用組,彙總和MapReduce但都被剛剛紡在圈子裏。
你想什麼做與其他領域如價格?最高價格?最低價格? – 2013-03-08 08:02:56
我不需要任何計算。我只是在尋找適用於特定時間點的文件。 – ReKo 2013-03-08 16:47:44