Home > front end >  How to use Map type in Attribute projections for DynamoDB
How to use Map type in Attribute projections for DynamoDB

Time:10-03

I'm trying to design a GSI for my table which contains a lot of data. However I know that its best practice to only project data that I need instead of the entire thing. Projecting data is pretty straight forward when it comes to Top-Level entities but in my use case I also need to project some of the contents of a map object

To give you more detail, here is my partial schema -

Name,
id,
url,
stats {
    revenue: {
        revenue: 123,
        total_orders: 123,
    }
    social: {}
    
}

and I want to project name, url and total_orders. Is there a way of projecting all three without projecting the whole stats object ?

CodePudding user response:

Sorry, no. You can only specify by name(s) what attribute to project.

CodePudding user response:

Only top level attributes can be projected. So for your case you would have 2 possible options:

  1. Project the entire stats map if it's not extremely large

  2. Write total_orders as a top level attribute. This would cause duplication but it would be negligible.

  • Related