0

Say I have to following document:

{
    "_id" : ObjectId("5dd7ae6ac48884404d3123be"),
    "startDate" : ISODate("2019-01-27T23:00:00.000Z"),
    "facility" : 1000100001,
    "endDate" : ISODate("2021-01-27T23:00:00.000Z"),
    "preCalcDates" : [ 
        {
            "start" : ISODate("2019-01-31T06:00:00.000Z"),
            "end" : ISODate("2019-01-31T13:00:00.000Z")
        }, 
        {
            "start" : ISODate("2019-02-01T06:00:00.000Z"),
            "end" : ISODate("2019-02-01T13:00:00.000Z")
        }, 
        {
            "start" : ISODate("2019-02-07T06:00:00.000Z"),
            "end" : ISODate("2019-02-07T13:00:00.000Z")
        }, 
        {
            "start" : ISODate("2019-02-08T06:00:00.000Z"),
            "end" : ISODate("2019-02-08T13:00:00.000Z")
        }, 
        {
            "start" : ISODate("2019-02-14T06:00:00.000Z"),
            "end" : ISODate("2019-02-14T13:00:00.000Z")
        }, 
        {
            "start" : ISODate("2019-02-15T06:00:00.000Z"),
            "end" : ISODate("2019-02-15T13:00:00.000Z")
        } 
    ],
    "__v" : 0
}

I want to find all documents with facility 1000100001 (also got others), return the whole document, except the entire field preCalcDates. From preCalcDates I want to return only the documents, that have "start" beween 2019-02-07 and 2019-02-14. How would I do that?

rStorms
  • 797
  • 1
  • 6
  • 18
  • @AlexBlex: Thanks! I posted edited code below, does this seem correct? – rStorms Nov 28 '19 at 10:59
  • yes, but why? The question has already been answered, has a decent number of upvotes for both the question and the answer, is well indexed and is returned in top3 results by google search. Just delete this one. – Alex Blex Nov 28 '19 at 11:27
  • It indeed works, thanks. Didn't find this questions, although I looked for it.. – rStorms Nov 28 '19 at 13:05

0 Answers0