Question

I'm using a Global Secondary Index to query my table and would like to be able to filter results based on other attributes (SQL equivalent would be a WHERE clause)). Scan allows me to do this, but is it possible with a Query? What other approaches can I take?

var params = {
                "IndexName": "City-index",
                "KeyConditions": {
                    "City": {
                        "AttributeValueList": [{
                            "S": city
                        }],
                        "ComparisonOperator": "EQ"
                    }

                },
                "Limit": "100",
                "TableName": "properties"
            }
            dynamoDB.query(params, function(err, data) {
                if (err) {
                    console.log(err);
                } else {
                    console.log(data);
                }

            });

Any other ideas of how I can design a TABLE to achieve:

Hash Key: propertyID (unique)
Range Key: createdAt (unique

Global Secondary Indexes: City
Global Secondary Indexes: State

I'd like to be able to query by an Index and then filter by other attributes (bedrooms, bathrooms, etc.)

Was it helpful?

Solution

Whichever attributes you need to query on needs to be made a GSI - You can add upto 5 of them. You need to also pay attention to the kind of queries it support (Only these: EQ | LE | LT | GE | GT | BEGINS_WITH | BETWEEN)

If your need is more than these queries, the Dynamo cant help - May be need to switch to RDS. If they can be formulated as documents, then consider Cloudsearch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top