1

I'm working on a project and we are using Dynamodb as database and i have a document with this structure :

{
   "shop_id": "hh-delightme",
   "shoppers": [
      {
        "email": "[email protected]",
        "name": "hatim haffane"
       },
       {
         "email": "[email protected]",
         "name": "bxdsf sdf sd f"
       }
     ]
  },{
   "shop_id": "it-delightme",
   "shoppers": [
       {
         "email": "[email protected]",
         "name": "hatim haffane"
        },
        {
         "email": "[email protected]",
         "name": "bxdsf sdf sd f"
        }
      ]
    }

i have two indexs the shop-id-index and email-index , so what i want to do is to get the shoper with the email "[email protected]" in the shop_id "hh-delightme"

i tried this code but without success

var params = {
            TableName:"shopper",
            KeyConditionExpression:"shop_id = :shop_id AND email = :email",
            ExpressionAttributeValues: {
                ":shop_id":store,
                ":email":email
            }

        };

        docClient.query(params, function(err, data) {}

can any one help me to get this done , thanks

1 Answer 1

2

I believe you cannot query two indexes at the same time. You can either change your query to a scan - but this will be slower as it will scan the whole table for each query - or you can query just one of your indexes. I'd query the index that you think will return the lowest number of results, probably email, and then filter the results in your nodejs code by shop_id.

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

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.