Hello. I want to know, whether Couchbase allows him to do what in Redis called “Sorted set” For instance, I have millions of sets each of them contains tens of documents. In Redis it is absolutely no problem to achieve, just make as many sets as I want.
But in Couchbase I did not found such feature, only Secondary Index. So I can only make one bucket and put all documents there, separated by index. For instance, in Redis:
Then I make composite index on (set, order) and query like
"SELECT * FROM my_bucket WHEREset='set1' ORDER BYorderDESC"
Will this work as Redis sets? Will it be fast on tens of millions documents with many inserts? I need ultra fast inserts and selects with same predicted speed regardless of the number of documents in buckets.
By putting the set name/id as the document key, lookup for an individual set uses an extremely fast key-value lookup, e.g.:
SELECT contents FROM my_bucket USE KEYS "set1";
If documents can appear in many different sets, it may be more space-efficient to store each document in Couchbase, and then put the document keys inside the set.
P.s. The JSON data model is quite flexible, and the best way to implement types like “set” or “list” depends a great deal on your specific requirements. If you implement something as an array,
{ "contents": [ "item1", "item2", "item3"] }
you get ordering for free, but searching for an item is O(size of array). But JSON objects behave a lot like Hashes or associative maps, but if order is important you would need to add that explicitly: