0

I am using DynamoDBMapper to insert a new object to my table. Table structure:

key: hash_key
attribute1: global sec index
other attributes

Now i want the value of attribute1 to be unique in the table. How to do that?

Already tried:

a. map.put("attribute1", new ExpectedAttributeValue(false));
b. map.put("atrribute1", new ExpectedAttributeValue().withExists(false));

I am using mapper.save() with default SaveBehaviour.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74
Gaurav Arora
  • 63
  • 1
  • 10

2 Answers2

0

you basically cannot do that with a GSI. The index does not say nothing about uniqueness. It just indexes the table for faster lookup based on that attribute

also see: DynamoDB key uniqueness across primary and global secondary index

Community
  • 1
  • 1
Mircea
  • 10,216
  • 2
  • 30
  • 46
0

If you're looking to enforce uniqueness on an attribute that's not the primary key, I would recommend taking a look at this post.

Community
  • 1
  • 1
Raymond Lin
  • 491
  • 2
  • 5