How to model data for sales per month?

Hi there,

I am still exploring the basic possibilities of fauna and try to find the “best”/new ways to handle data (indexes and/or Lambda).

My example:

  • One collection goods containing documents with name (apples, oranges)
  • One index “all_goods_by_name” forcing a unique name for goods
  • One collection sales
    Year, Month, reference to goods (i.e. apples), number of sales

Tasks:

  • Create/update sales document for each month and goods if it does not exist/update sales if it exists
  • Get sales by goods in timeframe “x”

Would you add more indexes to filter/handle the sales collection documents or is there a better approach? Restructuring data and/or using Lambda?

Thanks in advance

I think your model is fine, but given these requirements you are missing an index on.
‘sales_by_goods_and_timerange’.

That index will be an index on sales which indexes the ‘goods’ reference (since it’s an exact match, it’ll be a term on the index) since I assume your sale document will contain a reference to the goods document. The values of that index will need to start with the timestamp.

That brings us to another advice, depending on how you are going to do the range indexes you will need multiple indexes. You might just want to use a timestamp as well next to Year and Month to be a able to write different indexes depending on your requirements:

  • ‘sales_by_goods_and_timerange’.
  • ‘sales_by_goods_and_year’.
  • ‘sales_by_goods_and_month’.

All of this seems possible to me on first sight :slight_smile: