M
M
Michael2016-09-04 23:33:19
MongoDB
Michael, 2016-09-04 23:33:19

How to properly write a query in MongoDB?

Hello. I work with MongoDB on Node.js. The data is stored in this form:

{plants: 
   [ { name: 'ромашки',
       periodicity: 1,
       last: 2016-09-04T19:18:52.055Z,
       next: 2016-09-05T19:18:52.055Z },
       { name: 'бамбук',
       periodicity: 30,
       last: 2016-09-04T19:18:52.055Z,
       next: 2016-10-04T19:18:52.055Z }
 ],
  telegramID: 146444,
  time: '12:45' }

Is it possible to somehow write a query in such a way as to get users who have at least one array element in the plants field, whose field next = new Date()?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2016-09-05
@mak_ufo

db.users.find({"plants.next": new Date()})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question