2017-07-18 3 views
1

Let sagen, dass ich diesen Titel bekam in DynamoDB:entfernen verschachteltes Attribut in DynamoDB

{ 
    "customerId": "customer_001", 
    "customerName: "itsme", 
    "address": { 
    "city": "Frankfurt", 
    "country": "Germany", 
    "street1": "c/o Company xxx", 
    "street2": "Europe", 
    "street3": "PO Box 406", 
    "zip": "12345" 
    } 
} 

Und ich brauche, um verschachteltes Attribut address.street3 aus dem Elemente zu entfernen. Wie kann ich das erreichen?

Dies ist mein Code, es funktioniert perfekt, um nicht geschachteltes Attribut zu entfernen (zum Beispiel: customerName), aber wenn ich versuche, dies im verschachtelten Attribut zu verwenden (zum Beispiel: address.street3) funktioniert nicht (kein Fehler & nichts passiert auch)

const params = { 
    TableName: customerTable, 
    Key: { 
     customerId: customerId, 
    }, 
    AttributeUpdates: { 
     'address.street3': 
     { 
      Action: 'DELETE' 
     } 
    } 
}; 

dynamoDb.update(params, function (err, data) { 
    if (err) { 
     console.error("Unable to update customer. Error JSON:", JSON.stringify(err, null, 2)); 
    } 
    else { 
     console.log("UpdateCustomer succeeded:", JSON.stringify(data.Attributes)); 
     responseHelper.ResponseHelper.success(JSON.stringify(data.Attributes), 200, callback); 
    } 
}); 

Kann mir jemand helfen, was soll ich tun Attribut address.street3 entfernen?

Grüße

Antwort

2

Hier ist der Code "address.street3" Attribut zu entfernen.

var docClient = new AWS.DynamoDB.DocumentClient(); 

var params = { 
     TableName : "customer", 
     Key : { 
      "customerId": "customer_001"    
     }, 
     UpdateExpression : "REMOVE address.street3", 
     ReturnValues : "UPDATED_NEW" 
    }; 

console.log("Updating the item..."); 
docClient.update(params, function(err, data) { 
    if (err) { 
     console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2)); 
    } else { 
     console.log("UpdateItem succeeded:", JSON.stringify(data)); 
    } 
}); 
+0

es ist Arbeit. Vielen Dank :) – wapt49

Verwandte Themen