Search code examples
javaandroidkotlincouchbase-lite

Couchbase lite compound key range with nulls


I have view for my weather data with compound keys of the format

[ "District", "2018", "05", "23", "06", "00", "00" ]

On the server i can query weather for a day using a startkey and endkey

startkey=[ "District","2018","05","23",null,null,null]
endkey=[ "District","2018","05","23","\u0fff","\u0fff","\u0fff"]

This gives me all the weather for District on 2018-05-23. Now after syncing the documents to couchbase lite on android, i'm trying to replicate the key ranges. I have tried

startkey=arrayListOf("District","2018","05","23",null,null,null)
endkey=arrayListOf("District","2018","05","23","\u0fff","\u0fff","\u0fff")

But this returns an empty dataset. How can i format my keys to replicate what i did on the server.


Solution

  • Couchbase Server and Couchbase Lite has syntax difference for querying as it clearly depict the way we build the compound key array on the server side the null has been resolved to get the lexicographical correct value to output and the same happen with the Unicode provided in endKey Assuming your compound key

    [ "District", "2018", "05", "23", "06", "00", "00" ]
    [ "DistrictName","year","month","day","hour,"minute","second"]
    

    There might be two option on mobileside(Couchbase Lite) to query on such compound keys as dont provide the value for hour/min/second or Something more value representation for null and Unicode:

    From:

    startkey=arrayListOf("District","2018","05","23",null,null,null)
    endkey=arrayListOf("District","2018","05","23","\u0fff","\u0fff","\u0fff")
    

    To:

    startkey=arrayListOf("District","2018","05","23","00","00","01")
    endkey=arrayListOf("District","2018","05","23","23","59","59")