Fail to query Range

Hello, I have a problem executing a Range tells me that there is no data if I want to validate between two ranges of dates, these are stored in string format.

DB:
{
  "ref": Ref(Collection("scheduledKpis"), "275500105075786258"),
  "ts": 1598996224422000,
  "data": {
    "idSchedued": "bcf52c87-b75c-11ea-8739-dbd2f73c0e6a",
    "workId": "xxxxxx",
    "center": "1209",
    "plant": "xxxxx",
    "date": "2020-07-01",
    "work": "xxxxxx",
    "client": "xxxxxx",
    "timeToLoad": 0,
    "travelToClientDuration": 0,
    "waitingTimeInClient": 0,
    "unloadingTime": 0,
    "travelTimeBackToPlant": 0,
    "sapComplete": true,
    "volumen": 4,
    "statusId": "4"
  }
}



CreateIndex({
name: "scheduled_by_dates",
source: Collection("scheduledKpis"),
partitions: 8
})


Query:
client(key).query(
      q.Map(
        q.Paginate(
            q.Range(q.Match(q.Index('scheduled_by_dates')), "2020-07-04", "2020-07-10",)
        ),
        q.Lambda("scheduled", q.Select(["data", "date"], q.Get(q.Var("scheduled")) ))
      )
    )


Response:
{ data: [] }

Hi @Francisco_Murillo and welcome.

First of all, I notice you create the date field as a string. You should create as a Date:

 Create(Collection('scheduledKpis'),{data:{workId:'xxxxxxx',date:ToDate('2020-07-01')}})

at this point you can create an index this way:

CreateIndex(
  {
    name:'DateRef',
    source:Collection(<your collection>),
    values:[
      {field:['data','date']},
      {field:['ref']}
    ]
  }
)

and query that way:

Paginate(Range(Match('DateRef'),ToDate('2020-09-01'),ToDate('2020-09-05')))

Hope this helps.

Luigi

Hi @Luigi_Servini

it worked correctly, one more question I need in the answer that brings the data object complete with all its data

currently brings only the date.

Hi @Francisco_Murillo,

just use Map() and Lambda() to retrieve the matched documents:

Map(Paginate(Range(Match('DateRef'),ToDate('2020-09-01'),ToDate('2020-09-05'))),Lambda('doc',Get(Var('doc'))))

Hope this helps.

Luigi