usrlog
usrlog

Reputation: 13

Querying documents between dates (loopback 3 / mongodb)

I have documents with this structure:

{
        "_id": ObjectId("5c3defbdf58f1f001210169c"),
        "name": "Cristina",
        "created": "ISODate("2019-01-15T14:35:41.865Z")"
        "inscription": {
            "date": "ISODate("2019-01-15T14:35:41.865Z")"
        }
}

Using loopback sdk in my angular app I need to query for documents using the "inscription.date" property.

This code works:

this.usersApi.find({"limit":10,"skip":0,"order":"name ASC","where":{"created":{"gte":"2019-01-01T15:03:46.000Z","lte":"2019-01-24T15:03:46.000Z"}}})

But this code doesnt return any documents (and it should). I need to query for a nested property inside the incription object.

this.usersApi.find({"limit":10,"skip":0,"order":"name ASC","where":{"scheduleOfVisit.startTime":{"gte":"2019-01-01T15:06:56.000Z","lte":"2019-02-28T15:06:56.000Z"}}})

PS: Just ignore the values from the dates in the snippet code.

What I am doing wrong? Thanks in advance

Upvotes: 0

Views: 1080

Answers (1)

F3L1X79
F3L1X79

Reputation: 2665

From this ticket: https://github.com/strongloop/loopback/issues/517 filtering by nested properties only works as long as the nested properties are embedded on the same document.

If this is your case, have you tried using AND in your filters? Like:

    this.usersApi.find({
       "limit":10,
       "skip":0,
       "order":"name ASC",
       "where":{
           and: [
              {"scheduleOfVisit.startTime": {"gte":"2019-01-01T15:06:56.000Z"}},
              {"scheduleOfVisit.startTime": {"lte":"2019-02-28T15:06:56.000Z"}}
            ]
          }
     })

Upvotes: 1

Related Questions