返回

MongoDB Java使用聚合获取现有集合的架构

发布时间:2022-05-29 05:53:43 372
# php

我正在寻找解决方案来获取所有嵌套字段的字段名称和类型,包括使用 $project $mergeobjects、$objectToArray、$unwind 的文档数组。

collection.aggregate(Arrays.asList(

                new Document("$limit",100),

                new Document("$project", new Document("fields", new Document("$objectToArray", "$ROOT" ))),

                new Document("$unwind", "$fields"),

                new Document("$project", new Document("fields", new Document("k", "$fields.k").append("v",new Document("$type", "$fields.v")))),

                new Document("$group", new Document("_id", "$fields.k").append("fields", new Document("$first", "$fields"))),

                new Document("$group", new Document("_id", null).append("fields", new Document("$push", "$fields"))),

                new Document("$project", new Document("fields", new Document("$arrayToObject", "$fields" )))

                ));

我已经尝试实现但还无法处理文档数组。我正在尝试学习如何使用 $mergeObjects 来实现输出

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像