如何使用Java MongoDB驱动程序从文档列表访问值和字段?

时间:2018-07-13 16:16:29

标签: java mongodb

我正在使用MongoDB Java驱动程序,并且我已经花了将近一个小时的时间来研究如何处理文档列表并从中获取值,但是我没有找到适合我的东西。

下面是我的相关代码部分,以及我拥有的不同文档列表的精简控制台输出。如果有人可以解释如何从根本上对我的“ scoregot”值进行数组设置,将不胜感激,因为我无法理解那里的任何内容。

    List<Document> englishOut = (List<Document>) englishCollection.find()
            .projection(Projections.include("scoreout")).into(
                    new ArrayList<Document>());

    List<Document> englishGot = (List<Document>) englishCollection.find()
            .projection(Projections.include("scoregot")).into(
                    new ArrayList<Document>());

    List<Document> assignType = (List<Document>) englishCollection.find()
            .projection(Projections.include("scoretype")).into(
                    new ArrayList<Document>());

[文档{{__id = 5b3ec0d3beceb309d804ce7e,scoretype = quiz}}, 文档{{_id = 5b3ec18cbeceb309d804ce7f,scoretype = hw}},

[文档{{__id = 5b3ec0d3beceb309d804ce7e,scoreout = 25.0}},文档{{__id = 5b3ec18cbeceb309d804ce7f,scoreout = 5.0}},

[文档{{__id = 5b3ec0d3beceb309d804ce7e,scoret = 23.0}},文档{{__id = 5b3ec18cbeceb309d804ce7f,scoret = 5.0}},

0 个答案:

没有答案