soredive
soredive

Reputation: 813

mongodb find problem

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?

Upvotes: 1

Views: 306

Answers (1)

KaKa
KaKa

Reputation: 1553

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

Upvotes: 1

Related Questions