在$ push操作期间排序非文档嵌套数组的规范

时间:2017-06-12 21:15:56

标签: c# arrays mongodb sorting mongodb-.net-driver

给定文档结构:

[{
    _id: ObjectId("someId"),
    Property: {
        CollectionProperty: [{
            ItemKey: 28,
            StringArray: [
                "ItemA",
                "ItemB"
            ]
        }]
    }
}]

在mongo shell中执行以下操作可以实现我的目的:

db.getCollection('collection').updateOne(
{ 
    "_id" : ObjectId("someId"), 
    "Property.CollectionProperty.ItemKey" : 28 
}, 
{ $push : 
    { 
        "Property.CollectionProperty.$.StringArray" : { 
            $each : [ "AItemA" ], 
            $sort : 1
        }
     } 
});

但是,我无法在文档中或网上的任何地方找到如何在C#代码中重现THAT $ sort命令。我可以通过使用“field”:1来重现它,但不是那样的非文档数组。

描述该排序的mongodb文档在这里: MongoDB Sort Elements that are not documents

到目前为止,这是我在C#中所拥有的:

Builders<DataType>.Update.PushEach("Property.CollectionProperty.$.StringArray",
                new[] { "AItemA" }, null, null, ???)));

???是我不知道该怎么办...有没有人有任何建议?

TIA

1 个答案:

答案 0 :(得分:0)

这显然目前尚未得到支持,但计划在C#驱动程序中进行未来发布,如下所示:

https://jira.mongodb.org/browse/CSHARP-1271