I am trying to learn NoSQL with Google Datastore but I am running into a problem with uniqueness.
Consider an ecommerce store, it has categories and products.
<
Create a new kind called 'sku'. When you create a new product, you'll want to do a transactional insert of both the product entity and the sku entity.
For example, let's say you want to add a new product with the kind name product
with the id of abc
:
"product/abc" = {"sku": 1234, "product_name": "Test product"}
To ensure uniqueness on the property "sku", you'll always want to insert an entity with the kind name sku
and the id that equals the property's value:
"sku/1234" = {"created": "2017-05-11"}
The above example entity has a property for created date - just something optional I threw in as part of the example.
Now, as long as you insert both of these as part of the same transaction, you will be ensuring that the "sku" property has a unique value. This works because: