如何根据我的要求在任何NoSQL数据库中存储数据?

时间:2017-12-12 13:26:21

标签: json nosql

我是NoSQL数据库的新手。我正在设计我的NoSQL数据库的结构,可以满足我的要求,但我对如何构建和存储我的数据感到困惑。

以下是我在我的应用程序中使用的不同类型的文档。

1)简单的产品

{
  "available_qty": 5,
  "brand": "B1",
  "category": "C1",
  "id": 1,
  "image": {
    "id": 1,
    "image": "https://img1.etsystatic.com/209/0/10992508/il_fullxfull.1411756137_nsox.jpg",
    "tN": "https://img1.etsystatic.com/209/0/10992508/il_170x135.1411756137_nsox.jpg"
  },
  "incoming_qty": 0,
  "name": "Simple Product 1",
  "on_hand_qty": 10,
  "outgoing_qty": 5,
  "sku": "SP1",
  "status": 1,
  "tags": [
    {
      "color": "#258013",
      "id": 1,
      "name": "Mica Filling"
    }
  ],
  "tenant_id": 1,
  "type": 1
}

2)可配置产品

{
  "brand": "B1",
  "category": "C1",
  "id": 4,
  "image": {
    "id": 1,
    "image": "https://img1.etsystatic.com/209/0/10992508/il_fullxfull.1411756137_nsox.jpg",
    "tN": "https://img1.etsystatic.com/209/0/10992508/il_170x135.1411756137_nsox.jpg"
  },
  "name": "Configurable Product 1",
  "sku": "CP1",
  "tags": [
    {
      "color": "#258013",
      "id": 1,
      "name": "Mica Filling"
    }
  ],
  "tenant_id": 1,
  "type": 2,
  "variants": [
    {
      "available_qty": 5,
      "brand": "B1",
      "category": "C1",
      "id": 1,
      "image": {
        "id": 1,
        "image": "https://img1.etsystatic.com/209/0/10992508/il_fullxfull.1411756137_nsox.jpg",
        "tN": "https://img1.etsystatic.com/209/0/10992508/il_170x135.1411756137_nsox.jpg"
      },
      "incoming_qty": 0,
      "name": "Simple Product 1",
      "on_hand_qty": 10,
      "outgoing_qty": 5,
      "sku": "SP1",
      "status": 1,
      "tags": [
        {
          "color": "#258013",
          "id": 1,
          "name": "Mica Filling"
        }
      ],
      "tenant_id": 1,
      "type": 1
    },
    {
      "available_qty": 5,
      "brand": "B1",
      "category": "C1",
      "id": 2,
      "image": {
        "id": 1,
        "image": "https://img1.etsystatic.com/209/0/10992508/il_fullxfull.1411756137_nsox.jpg",
        "tN": "https://img1.etsystatic.com/209/0/10992508/il_170x135.1411756137_nsox.jpg"
      },
      "incoming_qty": 0,
      "name": "Simple Product 2",
      "on_hand_qty": 10,
      "outgoing_qty": 5,
      "sku": "SP2",
      "status": 1,
      "tags": [
        {
          "color": "#258013",
          "id": 1,
          "name": "Mica Filling"
        }
      ],
      "tenant_id": 1,
      "type": 1
    }
  ]
}

3)链接产品

{
  "id": 8,
  "linked_products": [
    {
      "available_qty": 5,
      "brand": "B1",
      "category": "C1",
      "id": 7,
      "image": {
        "id": 1,
        "image": "https://img1.etsystatic.com/209/0/10992508/il_fullxfull.1411756137_nsox.jpg",
        "tN": "https://img1.etsystatic.com/209/0/10992508/il_170x135.1411756137_nsox.jpg"
      },
      "incoming_qty": 0,
      "name": "Simple Product 7",
      "on_hand_qty": 10,
      "outgoing_qty": 5,
      "sku": "SP7",
      "status": 1,
      "tags": [
        {
          "color": "#258013",
          "id": 1,
          "name": "Mica Filling"
        }
      ],
      "tenant_id": 1,
      "type": 1
    },
    {
      "available_qty": 5,
      "brand": "B1",
      "category": "C1",
      "id": 6,
      "image": {
        "id": 1,
        "image": "https://img1.etsystatic.com/209/0/10992508/il_fullxfull.1411756137_nsox.jpg",
        "tN": "https://img1.etsystatic.com/209/0/10992508/il_170x135.1411756137_nsox.jpg"
      },
      "incoming_qty": 0,
      "name": "Simple Product 6",
      "on_hand_qty": 10,
      "outgoing_qty": 5,
      "sku": "SP6",
      "status": 1,
      "tags": [
        {
          "color": "#258013",
          "id": 1,
          "name": "Mica Filling"
        }
      ],
      "tenant_id": 1,
      "type": 1
    }
  ],
  "tenant_id": 1,
  "type": 6
}

这里Simple Product是根文档。 在可配置产品中,变体也是根文档。 在Linked Product中,linked_products也是根文档。

这意味着我将我的根文档嵌入其中。

我想实现这一点如果我查询available_qty = 5,它应该搜索简单的产品,可配置产品的变体以及Linked Product的linked_products。它也应该以同样的方式给我数据。

例如,我有1个可配置产品,包含5个变体,1个链接产品,3个linked_products& 10个简单的产品。现在,如果我的查询(即.available_qty = 5)与5个变体中的2个匹配,则它匹配3个简单的产品&它还匹配3个linked_products中的2个,然后它应该返回3个简单的产品,1个可配置的产品,2个变种& 1个链接产品和2个linked_products。

哪个NoSQL数据库最适合我?我应该如何构建我的数据?即具有id引用或嵌套文档的平根文档

0 个答案:

没有答案