It seems that kinvey does not support a specific date type.

How then should the dates be stored to make it possible to query between certain dates?

I am specifically interested in implementing this on their REST platform.

This mocha test seems to pass, however, I fear they are being filtered alphabetically and this may cause some edge cases that I have not thought of yet.

(note, there's boilerplate missing from the mocha test that I have abstracted to a common module)

describe(kinvey.description, function () {
    it('query between two dates', function (done) {
        var query = 'query={"date_of_birth":{"$gt" : "1948-01-01", "$lt" : "1948-08-19"}}&sort=last_name'
        kinvey.get('/appdata/' + kinvey.appKey + '/static?' + query, function (response, body) {
            assert.equal(body.length, 1)
            //john bonham
            assert.equal(body[0].first_name, 'John')
            assert.equal(body[0].last_name, 'Bonham')
            done()
        })
    })
})

Here is the test data I am playing around with.

Example data

(Could someone with enough reputation points add a Kinvey tag?)

有帮助吗?

解决方案

I'm part of the engineering team at Kinvey. As long as your date is in ISO-8601 format (https://en.wikipedia.org/wiki/ISO_8601), the dates will query correctly. Edge cases will occur if dates are not stored with all digits.

Example:

2012-02-08 will sort and query correctly, but 2012-2-8 will not.

As long as dates are in this format, query filters such as the below function correctly.

{"date_of_birth":{"$gt" : "1948-01-01", "$lt" : "1948-08-19"}}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top