简体   繁体   中英

Cassandra best practices when I need store json

suppose that I have different customers, anyone that send me an different json structure ie:

customer_1: {'name': ..., 'surname': ...}

customer_2: {'name': ..., 'address': ..., 'amount': ...}

customer_3: {'type': ..., 'amount': ..., 'color': ..., 'light': ...}

[...]

Actually I use MongoDB to store and work with this data, but for some reason I need to migrate to Cassandra. What is the best practices to store this data?

Option 1: I create an column family / table for any customer so any customer has its table and data structure

Option 2: I store all in an table, and every time I have an new customer (with an own json) I make an alter table to create new column?

Option 3: I store the json in one table, as map type, but in this way I cannot work with the single value

Option 2 sounds the most compatible with Cassandra. One table can keep track of all the customers as rows, and each field of the JSON can be a column. When you access a specific customer, it will only spit back the columns in which it has data. Empty columns are virtually free in Cassandra.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM