SimpleDB: Insert an item only if it does not already exist

I want to add a new item to the Amazon SimpleDB domain only if there is no item with the same item name yet.

I know how to do this for an attribute. But I want the element name to be checked to make sure that it is unique and that it will not overwrite the existing element - without an additional selection request, of course.

Attribute verification example:

https://sdb.amazonaws.com/
?Action=PutAttributes
&DomainName=MyDomain
&ItemName=JumboFez
&Attribute.1.Name=quantity
&Attribute.1.Value=14
&Attribute.1.Replace=true
&Expected.1.Name=quantity
&Expected.1.Exists=false
&AWSAccessKeyId=[valid access key id]
[...]

According to the FAQ, this should be possible:

"These semantics can also be used to implement functions such as counters, insert an element only if it does not exist [...]"

+3
source share
2 answers

, put SimpleDB Docs .

, , , , , , , put , item.

java, SDK amazon java, : -

// add a conditional check to ensure that the specified profile does not already
// exist - if there a timestamp, then this profile already exists
UpdateCondition condition = new UpdateCondition("quantity", null, false);

final PutAttributesRequest request = new PutAttributesRequest().withDomainName("MyDomain");
request.setItemName("JumboFez");
request.setAttributes(attributes);
request.setExpected(condition);

sdb.putAttributes (request);

, , , , , , "".

, , set true, puts , , replace = true ( , replace = true , replace = false .

+2

. % .

-1

Source: https://habr.com/ru/post/1791883/


All Articles