1

in user_history collection

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}]

I need to get food which has timestamp over 100

my code:

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

result:

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

result I want to get:

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

how could I get this?

soredive
  • 795
  • 1
  • 9
  • 25

1 Answers1

1

I dont think its possible,see the ticket: https://jira.mongodb.org/browse/SERVER-828. Looks like this question is already asked

Community
  • 1
  • 1
KaKa
  • 1,543
  • 12
  • 18