Mongo架构设计

发布于 2024-12-04 18:21:19 字数 759 浏览 7 评论 0原文

我对 Mongo 还很陌生。刚开始一个项目,使用Mongodb作为数据库。 我不确定应该如何为文档基础数据库设计以下用例。

用户案例
1. 供应商/分销商在我们的系统上有一个产品列表。
2. 每个产品都有一个适合任何客户的标准价格表。
3. 供应商/分销商还为每个客户定制每种产品的价格表。
例如。 CustA 有一个产品 A,其价格与标准价格不同,并且仅供他使用。 4. 某些产品只能通过自定义价格获得,我将这些产品与属性 public = false 进行匹配。

我应该如何在文档库数据库中解决这个问题?
我目前的设计是。
1. [产品文档]内嵌标准价目表文档。
2. [Product_Price 文档],带有 oneToMany 链接 [产品文档] 和 oneToMany 到 [客户文档]
3. [客户文档]。

使用这个模型,我面临着分页查询的问题。
示例我查询按名称排序的前 30 个产品。然后使用匹配的 30 个 ProductId 查询 [Product_Price Document],这样我就可以为登录的客户定制价格。

问题就出现在我无法查询定制商品的地方并非所有人都可以使用的用户。

有没有更好的方法或设计模式或者我应该如何处理查询?

我正在使用 PHP、Doctrine2、Symfony2

I'm pretty new to Mongo. Just started a project using Mongodb as the database.
I'm not sure how should i design the following use-case to a document base database.

User-Case
1. Vendor/Distributor has a list of product on our system.
2. There's a standard price list of each product for any customers.
3. Vendor/Distributor also has customize price list of each of the product for each customer.
eg. CustA have a productA at different pricing from the standard and it's only available to him.
4. Some of the Product are only available through customize price, and I match those product with attribute public = false.

How should i work this out in document base database?
Current design i have is.
1. [Product Document] with embedded document of standard price list.
2. [Product_Price Document] with oneToMany link [Product Document] and oneToMany to [Customer Document]
3. [Customer Document].

With this Model, I'm facing problem with querying by paging.
Example I query the first 30 Product sorted by name. Then query [Product_Price Document] with the 30 ProductId that match, so that I have those customize price for that customer who login.

The problems come where by I couldn't query item that are customize to the user that is not available for everyone.

Is there a better way or design the schema or what should i do with the query?

I'm using PHP, Doctrine2, Symfony2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赴月观长安 2024-12-11 18:21:19

当您查询 Product_Price_Document 时,使用 ProductID 和当前 CustomerID 进行查询。或者我错过了什么?

When you query the Product_Price_Document query it using both ProductID and current CustomerID. Or am I missing something?

谎言月老 2024-12-11 18:21:19

这是我将如何构建它。

有两个合集:
- 产品
- 供应商

您的产品表将列出您的所有产品及其标准价格。您的供应商页面将包含一系列产品 ID 以及覆盖价格,以防他们对该特定产品有不同的价格。

如果您也在跟踪客户,那么您也可以将其作为一个集合,并且几乎与供应商建立归属关系。

简而言之:

collection.vendor:
 {"name":'foo',"products":[{"_id":mongoId,"priceOveride":15.50},..]}

collection.products:
 {"name":"bar","price":15.40}

这是一个很好的资源,可以让您更多地了解您可以使用的关系:
交互式学习 Mongo

Here's how I would structure it.

Have two collections:
- Products
- Vendors

Your products table would have the list of all your products and their standard price. Your vendors page would have an array of product ID's along with an override price in the case that they have a different price for that particular product.

If you are also tracking customers then you could make that a collection too and have a belongs to relationship almost to the vendors.

so in short:

collection.vendor:
 {"name":'foo',"products":[{"_id":mongoId,"priceOveride":15.50},..]}

collection.products:
 {"name":"bar","price":15.40}

Excellent resource for reading a bit more into the relationships which you can use:
Learn Mongo Interactively

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文