Hello. Faced a problem There are documents of the form

{ _id: 5883e595e46735283e1cac1b, __v: 0, times: [ { week: 0, s: 1, e: 3, _id: 5883e595e46735283e1cac22 }, { week: 1, s: 3, e: 17, _id: 5883e595e46735283e1cac21 }, { week: 2, s: 0, e: 0, _id: 5883e595e46735283e1cac20 }, { week: 3, s: 5, e: 8, _id: 5883e595e46735283e1cac1f }, { week: 4, s: 0, e: 0, _id: 5883e595e46735283e1cac1e }, { week: 5, s: 7, e: 9, _id: 5883e595e46735283e1cac1d }, { week: 6, s: 0, e: 0, _id: 5883e595e46735283e1cac1c } ], createdAt: 2017-01-21T22:49:57.074Z } 

Need to get documents from which:

week = 3 s> = 5 e <= 9

Those. find the object in the array with week = 3, and see in the same object the values ​​of s and e, if their values ​​correspond to

 { s: { $gte: 6 }, e: { $lte: 7 } } 

Then find the entry above.

Is it possible to build such a condition?

    1 answer 1

    Here you will not believe, I killed half a day for this today. As soon as I wrote, I found a solution))

     times: { $elemMatch:{ week: 2, s: { $gte: 3 }, e: { $lte: 4 } } }