$push 操作期间非文档嵌套数组的排序规范
Sort Specification of Non-Document nested Array during a $push operation
给定文档结构:
[{
_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# 代码中重现 $sort 命令。如果它有字段,我可以通过使用 "field":1 重现,但不是像那样的非文档数组。
描述该排序的 mongodb 文档位于此处:
MongoDB Sort Elements that are not documents
到目前为止,这是我在 C# 中的内容:
Builders<DataType>.Update.PushEach("Property.CollectionProperty.$.StringArray",
new[] { "AItemA" }, null, null, ???)));
那个???是我不知道该怎么做...有人有什么建议吗?
TIA
这显然目前不受支持,但计划在 C# 驱动程序的未来版本中提供,如此处所述:
给定文档结构:
[{
_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# 代码中重现 $sort 命令。如果它有字段,我可以通过使用 "field":1 重现,但不是像那样的非文档数组。
描述该排序的 mongodb 文档位于此处: MongoDB Sort Elements that are not documents
到目前为止,这是我在 C# 中的内容:
Builders<DataType>.Update.PushEach("Property.CollectionProperty.$.StringArray",
new[] { "AItemA" }, null, null, ???)));
那个???是我不知道该怎么做...有人有什么建议吗?
TIA
这显然目前不受支持,但计划在 C# 驱动程序的未来版本中提供,如此处所述: