Mongodb c#driver - AggregateToCollectionOperation
我正在使用库 MongoDB.Driver 2.8.1 (我计划升级到最新版本,这是一个旧项目)。
我试图在我的代码中使用运算符 $out 进行查询,所以我编写了这段代码(这不是很好,但这不是问题)
await collectionAcc.Aggregate().AppendStage<BsonDocument>(@"{
$unwind: {
path: ""$Packs"",
preserveNullAndEmptyArrays: false
}
}")
.AppendStage<BsonDocument>(@"{
$replaceRoot: {
newRoot: { $mergeObjects: [ ""$$ROOT"", {""Sku"" : ""$Packs.Sku"" }, {""SizePack"" : ""$Packs.Size"" } ] }
}
}")
.AppendStage<BsonDocument>(@"{ $out: ""accessoryPacks"" }").FirstOrDefaultAsync();
我运行它并出现此错误: “AggregateOperation 的管道包含一个 $out 运算符。请使用 AggregateOutputToCollectionOperation 代替”
很好,我尝试使用 AggregateOutputToCollectionOperation 类,但我根本没有找到任何文档,也没有一个像样的示例。
有人可以帮助我吗?
I'm using the library MongoDB.Driver 2.8.1 (i'm planning to upgrade to the latest version, it's an old project).
I'm trying to use the operator $out for a query in my code so I wrote this piece of code (it's not wonderful, but it's not a problem)
await collectionAcc.Aggregate().AppendStage<BsonDocument>(@"{
$unwind: {
path: ""$Packs"",
preserveNullAndEmptyArrays: false
}
}")
.AppendStage<BsonDocument>(@"{
$replaceRoot: {
newRoot: { $mergeObjects: [ ""$ROOT"", {""Sku"" : ""$Packs.Sku"" }, {""SizePack"" : ""$Packs.Size"" } ] }
}
}")
.AppendStage<BsonDocument>(@"{ $out: ""accessoryPacks"" }").FirstOrDefaultAsync();
I run it and this error appear:
"The pipeline for an AggregateOperation contains a $out operator. Use AggregateOutputToCollectionOperation instead"
Good, I try to use AggregateOutputToCollectionOperation class but I found no documentation at all, nor a decent example.
Someone can help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,我错过了您调用
FirstOrDefault
的事情。$out
和$merge
应该是管道中的最后阶段,但 FirstOrDefault 在它们之后另外添加了{ limit : 1 }
阶段。您应该在$out
之前在管道内添加此阶段oh, I missed that you call
FirstOrDefault
.$out
and$merge
should be the last stages in pipeline, but FirstOrDefault additionally adds{ limit : 1 }
stage after them. You should add this stage inside pipeline before$out