如何在MongoDB中正确设计模型结构?

时间:2018-08-29 17:33:08

标签: node.js mongodb mongoose

我从SQL数据库开始进行MongoDB设计。我正在尝试构建一个简单的应用程序,但不确定如何正确设计模型结构。这就是我想要实现的原因-我有一篇属于用户且属于某个类别(后来可能属于许多类别)的文章

我从SQL开始自动构建的结构如下:

import pandas as pd
dictDF = pandas.DataFrame.from_dict(sc.parallelize(mapOfVectors))

我看过一些教程,也看到了设计模型结构的可能性:

@Bean
public Step sampleStep(PlatformTransactionManager transactionManager) {
        return this.stepBuilderFactory.get("sampleStep")
                                .transactionManager(transactionManager)
                                .<String, String>chunk(10)
                                .reader(itemReader())
                                .writer(itemWriter())
                                .build();
}

在这里设置{ "_id" : ObjectId("5b85e3e2b16d72c70e3e96ef"), "price" : 40, "name" : "2st Article", "location" : "Paris, France", "categoryId" : ObjectId("5b81f12725f15a490f46ed81"), "userId" : ObjectId("5b81f127idsg283efb1"), "description" : "abc...", "createdAt" : ISODate("2018-08-29T00:08:02.022Z"), "updatedAt" : ISODate("2018-08-29T00:08:02.022Z"), "__v" : 0 } 的相同方式(将来,文章可能属于多个类别)也可以对{ "_id" : ObjectId("5b85e3e2b16d72c70e3e96ef"), "price" : 40, "name" : "2st Article", "location" : "Paris, France", "categoryIds" : [ { ObjectId("5b81f12725f15a490f46ed81") } ], "userId" : ObjectId("5b81f127idsg283efb1"), "description" : "abc...", "createdAt" : ISODate("2018-08-29T00:08:02.022Z"), "updatedAt" : ISODate("2018-08-29T00:08:02.022Z"), "__v" : 0 } 进行设置。

我仍然不确定哪种方法对我的用例更好(或最好)。我要处理的数据-过滤时间范围内的所有文章,按类别,作者(用户)等过滤文章。

哪种结构更适合此用例?

0 个答案:

没有答案