如何将此聚合代码转换为.NET或c#?

时间:2017-10-12 01:00:03

标签: vb.net mongodb

将此代码转换为.NET时遇到一些麻烦。它位于两个[ ]

之间
db.account.aggregate([   {     $group: {       _id : null,       total: {$sum: 1},       "Pricebook ID": {$addToSet: "$Pricebook ID"},     },   },{     $project: {       "Pricebook ID":  { $eq:  [ "$total", {$size: "$Pricebook ID"}  ] }     }   } ]);

目前,这是.NET中的代码。谁知道最后一部分?

Dim Aggregate = Collection.Aggregate.
                          Group(
                                New BsonDocument From
                                      {
                                            {"_id", BsonNull.Value},
                                            {"total", New BsonDocument From
                                                  {
                                                        {"$sum", 1}
                                                  }
                                            },
                                            {"Pricebook ID", New BsonDocument From
                                                  {
                                                        {"$addToSet", "$Pricebook ID"}
                                                  }
                                            }
                                      }
                          ).
                          Project(
                                New BsonDocument From
                                {
                                      {"Pricebook ID", New BsonDocument From
                                            {
                                                  {"Pricebook ID", New BsonDocument From
                                                        {
                                                              {"$eq", <code here>}
                                                        }
                                                  }
                                            }
                                      }
                                }
                          )

谢谢!

1 个答案:

答案 0 :(得分:0)

由于这一点,我能够弄清楚自己:MongoDB Aggregation Pipeline C#

答案:

Dim Aggregate = Collection.Aggregate.
                          Group(New BsonDocument From {
                                            {"_id", BsonNull.Value},
                                            {"total", New BsonDocument From {
                                                        {"$sum", 1}}},
                                            {"Pricebook ID", New BsonDocument From {
                                                        {"$addToSet", "$Pricebook ID"}}}}
                          ).
                          Project(
                                New BsonDocument From {
                                      {"Pricebook ID", New BsonDocument From {
                                                  {"$eq", New BsonArray From {
                                                              "$total", New BsonDocument From {
                                                                    {"$size", "$Pricebook ID"}}}}}}}
                         )