Query for latest records of a given set of users

Try this. You’ll get the both the max time and the document ID associated with it. Important to set the attribute names within max correctly so time gets compared first.

select max({"a":time, "b":META(mybucket).id}) as timex, uid from mybucket where api == “testkey” and kind == “record” and uid in [ “todd”, “foo”, “foo1” ] group by uid order by timex desc