Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
Looking for the most efficient/cost effective way to query my DynamoDB table

On my website I have a form with the fields: full name, email, phone #, and message (image below).

enter image description here

After someone fills out the form, I want to query my table to see if there are any items with the same email address, or phone # that the user gave to the form. If there IS an item with the same email/phone # then I want to retrieve that item’s "sharedID", then create a new item in the table with the submitted form information as well as the retrieved id.

enter image description here

Currently, I’m performing a dynamoDB query to achieve this (code below). However, I believe that I need to include the primary key (id) in the query. However, this is a problem because there’s no way of knowing an item’s id when querying (being that the id’s are randomly generated).

const checkForSameEmailOrPhone = () => {

const params = {
 TableName: "customers",
 ProjectionExpression: "sharedID",
 FilterExpression: "email_address = :givenEmail or phone_number = :givenNumber",
 ExpressionAttributeValues: {
     ":givenEmail": "xample@example.com",
     ":givenNumber": '7777777'
 }
};

docClient.query(params, function(err, data){
   if (err) {
     console.error('Error in GetItem', err);
   } else {
     console.log('data', data);
     function createItem() {
       const uniqueId = nanoid();
         let params = {
             TableName :"customers",
             ConditionExpression: "attribute_not_exists(z)",
             Item:{
               "id": uniqueId,
               "email_address": "address@email.com",
               "full_name": "a name",
               "phone_number": "822222222",
               "message": "different",
               "sharedId": data?.Items[0]?.id || uniqueId
             }
         };
         docClient.put(params, function(err, data) {
             if (err) {
               console.error('sdk ERROR', err);
             } else {
               console.log('success');
             }
         });
     };
     createItem();
   }
});
};

That being said, I was wondering if anyone could help me find a cost effective/efficient solution to retrieve the id of an item which contains the same email and phone # the user gave on the form.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should create Global Secondary Indexes and use the fields that you want to query by as partition keys. You can have multiple GSI for a table and the best practice is to add only the necessary fields to the index (so you use less read capacity units when querying the data). You can read more about the indexes in the official documentation

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda