Saurav Pathak
Saurav Pathak

Reputation: 836

How to make combination of keys unique in mongokit document?

Database structure looks like this.

from mongokit import Document

class FlashscoreNameMap(Document):
    structure = {
        "flashscore_name": basestring,
        "translated_name": basestring,
        "player_id": basestring,
        "timestamp": float
    }
    default_values = {
        "translated_name": '',
        "player_id": ''
    }
    indexes = [
    # How do I declare validation rules here? 
    ]
    use_dot_notation = True

Validation Rules to be enforced

  1. player_id can be '' empty string, or else it should be unique. I've heard the term sparse for this. (It need not be unique if it is empty string. This is important.)
  2. Combination of flashscore_name and player_id should be unique.

Any help is appreciated. In case of duplicates, I want to update value of translated_name.

Upvotes: 1

Views: 20

Answers (0)

Related Questions