Buildfire - Trouble with Query Selectors

68 Views Asked by At

I have two unix timestamps, a start time (startDate) and an end time (endDate). Using the moment function below gives me the very start/end of the day:

search = {
  "end": { "$lte": moment(endDate).startOf('day').unix() },
  "start": {"$gte": moment(startDate).startOf('day').unix() }
};

I then pass my search into my buildfire function:

buildfire.publicData.search(search ,'routes', (err, res) => {})

My res is an array of objects, each has a data property with a start and end property inside of that:

res = [
  {
    data: {
      end: 1503554370297,
      start: 1503554368711
    }
  }
]

All results are returning, nothing is being filtered.

1

There are 1 best solutions below

5
On BEST ANSWER

Here is the docs datastore search https://github.com/BuildFire/sdk/wiki/How-to-use-Datastore#buildfiredatastoresearchoptions-tag-optional-callback

I believe you are not sending the filter correctly.

You are sending:

search = {
  "end": { "$lte": moment(endDate).startOf('day').unix() },
  "start": {"$gte": moment(startDate).startOf('day').unix() }
};
buildfire.publicData.search(search ,'routes', (err, res) => {})

And it should be more like

var options = {
  "filter":{
        "$json.end": { "$lte": moment(endDate).startOf('day').unix() },
        "$json.start": {"$gte": moment(startDate).startOf('day').unix() }
  }
};
buildfire.publicData.search(search ,'routes', (err, res) => {})

Basically since your filter property in your options objectis undefined it returns everything