[英]How to handle tags in a noSQL database
I have a noSQL db with products. 我有一个带有产品的noSQL数据库。 These products obviously have some characteristics and I can filter the products out by their properties. 这些产品显然具有一些特性,我可以根据其属性过滤产品。
How does this work with tags? 这如何与标签一起使用? More specifically, how should I structure the nodes such that I can filter out items with a specific tag? 更具体地说,我应该如何构建节点,以便我可以过滤掉具有特定标签的项目?
Firebase 火力地堡
Follow up if you are familiar with Firebase .equalTo(): how would I structure my FB db and how would I query out items with a specic tag? 如果您熟悉Firebase .equalTo(),请跟进:如何构建我的FB数据库以及如何查询带有特定标记的项目?
One thing I was thinking of is to have seperate properties for the nodes, eg: 我想到的一件事是为节点提供单独的属性,例如:
$productId
/tag_1
/tag_2
But then I have to filter or query multiple times. 但后来我必须多次过滤或查询。 How can this be overcome or are there other ways? 如何克服或有其他方法?
You're putting the tags
underneath the products
. 您将tags
放在products
下面。 Try flipping it. 尝试翻转它。
$tagId
/$productId
Now you can find a product by a tag without a query. 现在,您可以通过标签查找产品而无需查询。
// https://<my-firebase-app>.firebaseio.com/tags/{tag}/{productId}
var ref = new Firebase('url').child('tags').child($tagId).child($productId);
The JSON would look like this: JSON看起来像这样:
{
"tags":{
"kinda_cool":{
"product_3":true,
"product_6":true
},
"super_cool":{
"product_1":true,
"product_2":true,
"product_4":true,
"product_5":true
}
}
}
Rather than true you could store any other relevant information. 而不是真实,你可以存储任何其他相关信息。 But having the $productId
as the key you can easily retrieve a product by it's tag. 但是以$productId
作为键,您可以通过它的标签轻松检索产品。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.