mongodb找到问题

时间:2011-07-28 03:52:05

标签: mongodb

<_>在user_history集合中

user_name: john
eat : [{food:'apple', timestamp:123}, {food:'cheese', timestamp:80}]

user_name: paul
eat : [{food:'melon', timestamp:125}, {food:'bread', timestamp:60}]

user_name: mattew
eat : [{food:'water', timestamp:90}, {food:'pizza', timestamp:91}]

我需要获得时间戳超过100的食物

我的代码:

db.user_history.find({"eat.timestamp":{$gte:100}},{"eat.food":1})

结果:

{'_id': ObjectId('......'),'eat':[{food:'apple'},{food:'cheeza'}]},
{'_id': ObjectId('......'),'eat':[{food:'melon'},{food:'bread'}]}

我想得到的结果:

{'_id': ObjectId('......'), 'eat':{food:apple}},
{'_id': ObjectId('......'), 'eat':{food:melon}}

我怎么能得到这个?

1 个答案:

答案 0 :(得分:1)

我认为不可能,请看门票:https://jira.mongodb.org/browse/SERVER-828。 看起来这个问题是already asked