Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

biswa333_125242 avatar image
biswa333_125242 asked ·

Which collection should I use to store names of products?

you want to use a collection that hold the product name for various products. if you want to query that will find order of sequence in which product is ordered --which type of collection you would use

  • MAP
  • SET
  • LIST
cassandracollections
1 comment
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

You can use SET because the values of a set are stored unordered, but will return the elements in sorted order when queried.

https://docs.datastax.com/en/cql-oss/3.3/cql/cql_using/useSet.html


0 Likes 0 · ·
vikram.singh.chouhan_187371 avatar image
vikram.singh.chouhan_187371 answered ·

Hi @biswa333_125242:

As suggested by other please be more specific to your requirement.

As far as I understood, you want to store orders placed against some key and like to keep the track of orders by date placed, also the product could be ordered multiple times. If so then using List could be a good choice to maintain natural creation date order. Cheers!!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

saravanan.chinnachamy_185977 avatar image
saravanan.chinnachamy_185977 answered ·

@biswa333_125242 I could not understand your requirements clearly. The various collection choices and their uses are as listed below.

  • LIST
    • Element order is maintained (may not be the natural order of the elements)
    • It supports storing same value multiple times.
    • List values are returned according to their index value in the list.
  • SET
    • A set stores a group of elements that are returned in sorted order when queried.
    • It does not allow storing duplicate elements.
    • Values are returned in alphabetical order when queried, assuming the values are text.
  • MAP
    • It stores key-value pairs.
    • For each key, only one value may exist.
    • A map is a (sorted) set of key-value pairs, where keys are unique and the map is sorted by its keys.

You can review your requirements and map the right collection type to use. Or please feel free to update the question with more details and we can provide further details.

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.