MongoDB,右投影子字段

时间:2017-06-24 19:14:32

标签: java mongodb java-8 java-api

我有像这个例子的集合

 { "_id" : { "$oid" : "594989c638773060134b8442" },
"rank" : 10.0, "brand" : "Dodge", "model" : "Viper",
"engineSpec" : { "cylinderConfig" : "V-10", "engineLiters" : 8.4, "transmission" : "6 speed manual" } }

如果我提出请求

 collection.find()
.projection(Projections.include("engineSpec"))
.forEach((Block<Document>) set ->{
                System.out.println(set.toJson());
            });

我喜欢这个

{ "_id" : { "$oid" : "594989c638773060134b8442" },
"engineSpec" : { "cylinderConfig" :
"V-10",
"engineLiters" : 8.4,
"transmission" : "6 speed manual" } }

我想得到这个例子中的集合

{ "_id" : { "$oid" : "594989c638773060134b8442" },
"engineSpec" : {"transmission" : "6 speed manual" } }

0 个答案:

没有答案