3

Folks, I have the following table:

  hashKey (model):   RangeKey (make):
  mustang            ford
  f150               ford
  malibu             chevy
  ...

What I would like to do is search and return all Ford models, ie:

var params = {
        TableName : 'models',
        IndexName : 'make-index',
        KeyConditions : 
        {
            "make" : 
            {
                "AttributeValueList" : [
                {
                    "S" : 'ford'
                }
                ],
                "ComparisonOperator" : "EQ"
            }
        },
    }
    db.query(params, function(err, data) {
        if (err) {
            console.log (err)
            callback(err, null)
        } else {
            callback(null, data.Items)
        }
    });

What am I doing wrong? :) Thanks!

1
  • I am trying to avoid the way i know how to build this table... ie entry make model If i make hashkey a known string, then i can certainly query. but this seems like a non-aws way of using dynamo Commented Apr 5, 2014 at 6:59

2 Answers 2

2

Have you set up a global secondary index with make as the hash key of the index? Your query is telling DynamoDB to use an index named make-index, but it's not clear from your question whether that index exists.

The only way to use the Query operation in DynamoDB is using an EQ operator on a hash key. That could be on the hash key on the table, or a hash key on a global secondary index, but there's no way (without a global secondary index) to construct a query that says "give me all the items whose range key is ford." If you have a global secondary index set up with make as the hash key, then you could perform the query you've described.

Unfortunately, indexes can only be created when the table is created. If you don't have a global secondary index on the make item, then you could accomplish it with a Scan operation, but it won't be as performant as a Query.

Sign up to request clarification or add additional context in comments.

Comments

-1

You can make global secondary indexes after a table is made. Go to the amazon aws dynamodb console, click on a table and click "create index."

You can find the amazon aws console by typing "amazon aws" into google.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.