我想将链接存储在 Firebase 表中。我希望它们是独一无二的。这些链接也将被其他表引用,因此我不希望每次引用链接时都必须存储链接的整个长 URL 字符串。我很难找到一种方法来强制链接的唯一性,同时还使用相对较短的键来引用它们。
例如,给定以下架构:
{
"comments" : {
"-JYC6EkXz5DZt7s5jFMT" : {
"content" : "This is the first comment.",
"createdAt" : 1412190501922,
"link" : "http---testing-com-1-some-article",
"userId" : 0
},
"-JYC6EmzCoKfYol1Ybyo" : {
"content" : "This is a reply to the first.",
"createdAt" : 1412190502079,
"link" : "http---testing-com-1-some-article",
"replyToCommentId" : "-JYC6EkXz5DZt7s5jFMT",
"userId" : 1
},
"-JYC6Ep9lwdAwQbZmdYH" : {
"content" : "This is a reply to the second.",
"createdAt" : 1412190502218,
"link" : "http---testing-com-1-some-article",
"replyToCommentId" : "-JYC6EmzCoKfYol1Ybyo",
"userId" : 0
}
},
"links" : {
"http---testing-com-1-some-article" : {
"comments" : {
"-JYC6EkXz5DZt7s5jFMT" : true,
"-JYC6EmzCoKfYol1Ybyo" : true,
"-JYC6Ep9lwdAwQbZmdYH" : true
},
"createdAt" : 1412190501880,
"url" : "http://testing.com/1/some_article"
}
},
"users" : [ {
"comments" : {
"-JYC6EkXz5DZt7s5jFMT" : true,
"-JYC6Ep9lwdAwQbZmdYH" : true
},
"createdAt" : 1412190501881,
"name" : "Joe Blow"
}, {
"comments" : {
"-JYC6EmzCoKfYol1Ybyo" : true
},
"createdAt" : 1412190501881,
"name" : "Jack Black"
} ]
}
如您所见,每条评论都必须包含其所属链接的长键。有没有一种在保持唯一性的同时缩短这些键的好方法?