我正在使用Google App Engine和Big Table。在大表中,子(子)集合中的鍵值是否正常?
我有一個person
實體,看起來像這樣:
{
// This property would be encoded into JSON and saved un-indexed as db.Text()
phone_numbers:
{
'hHklams8akjJkaJSL': // <-- Should I key this object?
{
number:'555-555-5555',
type:'mobile',
},
etc...
},
// This property is an array of strings.
// It is searchable so that a query could be run to find all
// people with a particular phone number:
// "SELECT * FROM person WHERE phone_number_search_property =
// '5555555555'"
phone_number_search_property:['5555555555','other phone numbers...'],
first_name:'...',
etc...
}
的phone_number
屬性被存儲爲JSON格式文本未加索引(db.Text)的斑點。如果我想在這種情況下引用特定的電話號碼,我將解碼json,然後用我正在查找的特定密鑰獲取電話號碼。
phone_number_search_property
用於搜索。它可以通過電話號碼搜索:"SELECT * FROM person WHERE phone_number_search_property = '5555555555'"
在這種情況下,在實體內引用電話號碼的好方法是什麼?在這裏,我使用UUID鍵入每個值。這是否是一種「正常」且被接受的做事方式?如果不是,那是什麼?
謝謝!
嘿,彼得,我用UUID鍵入鍵值,因爲我試圖養成一種不對數據本身進行鍵控的習慣。有時我認爲獨一無二的信息是不可能的。在這種情況下,我必須鍵入電話號碼和分機號碼,而不僅僅是電話號碼。如果有人想製作一個主要公司的電話號碼,那麼這可能會導致問題,然後在描述中: 「Ask for Carol」。如果有人輸入了錯誤的數字,然後對其進行了更正,這也會很煩人,該項目將不得不重新鍵入。 – 2012-03-12 13:04:03