私はmongoドキュメントを別のドキュメントに投影しようとしています。値がフィールド "v"のオブジェクトに格納されている場所の下の文書を考えてみましょう。私はそれらの価値をより高いレベルに戻したいと考えています。私は以下の投影jsonでほとんどのフィールドを行う方法を知っています。しかし、要素が実際に値であり、名前が設定されていないdtone領域の投影jsonを理解することはできません。だから私はどのように値を投影するのですか?サブプロジェクト名が値であるmongoパイプラインでのプロジェクト方法
{
"_id" : "58e7a9d4418bcb55804d5756",
"fullName" : {
"v" : "Julie Johnson",
"tags" : [ "C" ]
},
"guid" : {
"v" : "21d5a58c-39fb-489b-8d3a-46729ab387e2",
"tags" : [ "U", "C"]
},
"dtones" : {
"20170301" : {
"tone" : {
"v" : 1.37947514772332,
"tags" : ["U"]
},
"plus" : {
"v" : 3.39437782412235,
"tags" : ["U", "C"]
}
},
"20170302" : {
"tone" : {
"v" : 1.14849248571483,
"tags" : ["U"]
},
"plus" : {
"v" : 2.51859894690038,
"tags" : ["U", "C"]
}
}
}
}
所望の文書には、次のとおりです。
{
"_id" : "58e7a9d4418bcb55804d5756",
"fullName" : "Julie Johnson",
"guid" : "21d5a58c-39fb-489b-8d3a-46729ab387e2",
"dtones" : {
"20170301" : {
"tone" : 1.37947514772332,
"plus" : 3.39437782412235
},
"20170302" : {
"tone" : 1.14849248571483,
"plus" : 2.51859894690038
}
}
}
マイプロジェクトJSONは
{
"_id": 1,
"fullName": "$fullName.v",
"guid": "$guid.v",
"dtones": <--- what goes here to map the variable element names
}
のように見え、私の.NETパイプラインのコードは次のようになります。
pipeline = collection.Aggregate()
.AppendStage<BsonDocument>(matchJson)
.AppendStage<BsonDocument>(redactJson)
.AppendStage<BsonDocument>(projectionJson);
ありがとうございました。私はまた、ドキュメントを修正してから、アプリケーションが期待するものにそれを投影することも考えています – KenB