haffane hatim
haffane hatim

Reputation: 474

search inside a list in dynamodb using nodejs

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

Upvotes: 1

Views: 333

Answers (1)

Mark Hayward
Mark Hayward

Reputation: 444

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.

Upvotes: 2

Related Questions